blob: f4000022954b4e535de89cf6bf429875042f3b30 (
plain) (
tree)
|
|
package barcode
import (
"strconv"
"strings"
"github.com/neonxp/checksum"
)
// Check barcode
func Check(number string) error {
sum := 0
numbers := strings.Split(number, "")
l := len(numbers)
for i := l; i > 0; i-- {
ch := numbers[i-1]
num, err := strconv.Atoi(string(ch))
if err != nil {
return checksum.ErrInvalidNumber
}
if (l-i)%2 != 0 {
sum += num * 3
} else {
sum += num
}
}
if sum%10 != 0 {
return checksum.ErrInvalidChecksum
}
return nil
}
func Generate(number string) (string, error) {
return "", checksum.ErrNotImplemented
}
|