moved checksum function to its own interface

its not needed that all barcodes have an integer checksum
so it should not be needed in every implementation.
This commit is contained in:
Florian Sundermann committed 2017-01-26 08:20:38 +01:00
1 parent fe0f26ff6d
commit b066487b3e
11 files changed
+57 -34

No files matched your search

+3 -3
View File
@@ -158,7 +158,7 @@ func encodeEAN13(code string) *utils.BitList {
}
// Encode returns a EAN 8 or EAN 13 barcode for the given code
func Encode(code string) (barcode.Barcode, error) {
func Encode(code string) (barcode.BarcodeIntCS, error) {
var checkSum int
if len(code) == 7 || len(code) == 12 {
code += string(calcCheckNum(code))
@@ -175,12 +175,12 @@ func Encode(code string) (barcode.Barcode, error) {
if len(code) == 8 {
result := encodeEAN8(code)
if result != nil {
return utils.New1DCode("EAN 8", code, result, checkSum), nil
return utils.New1DCodeIntCheckSum("EAN 8", code, result, checkSum), nil
}
} else if len(code) == 13 {
result := encodeEAN13(code)
if result != nil {
return utils.New1DCode("EAN 13", code, result, checkSum), nil
return utils.New1DCodeIntCheckSum("EAN 13", code, result, checkSum), nil
}
}
return nil, errors.New("invalid ean code data")