Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidArgument = errors.New("checkdigit: invalid argument")
ErrInvalidArgument is happening when given the wrong argument.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
func NewJAN13 ¶
func NewJAN13() Provider
NewJAN13 returns a new Provider that implemented GTIN-13 with position correction calculator.
func NewLuhn ¶
func NewLuhn() Provider
Example ¶
package main
import (
"fmt"
"log"
"strconv"
"github.com/178inaba/tech-playground/checkdigit"
)
func main() {
p := checkdigit.NewLuhn()
const seed = "411111111111111"
cd, err := p.Generate(seed)
if err != nil {
log.Fatalln("failed to generate check digit")
}
ok := p.Verify(seed + strconv.Itoa(cd))
fmt.Printf("seed: %s, check digit: %d, verify: %t\n", seed, cd, ok)
}
Output: seed: 411111111111111, check digit: 1, verify: true
Click to show internal directories.
Click to hide internal directories.