Implement EAN and improve Code39 error handling
This commit is contained in:
parent
54fa0d34ad
commit
0b2effd135
@ -8,11 +8,12 @@ import (
|
||||
)
|
||||
|
||||
func generateCode39(parameters Parameters) (barcode.Barcode, error) {
|
||||
var strippedBarcode barcode.Barcode
|
||||
GeneratedBarcode, err := code39.Encode(parameters.Content, true, true)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating Barcode", err)
|
||||
} else {
|
||||
strippedBarcode = GeneratedBarcode.(barcode.Barcode)
|
||||
}
|
||||
|
||||
strippedBarcode := GeneratedBarcode.(barcode.Barcode)
|
||||
return strippedBarcode, err
|
||||
}
|
||||
|
20
generation/ean.go
Normal file
20
generation/ean.go
Normal file
@ -0,0 +1,20 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/ean"
|
||||
)
|
||||
|
||||
func generateEAN(parameters Parameters) (barcode.Barcode, error) {
|
||||
var strippedBarcode barcode.Barcode
|
||||
GeneratedBarcode, err := ean.Encode(parameters.Content)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating Barcode", err)
|
||||
} else {
|
||||
strippedBarcode = GeneratedBarcode.(barcode.Barcode)
|
||||
}
|
||||
|
||||
return strippedBarcode, err
|
||||
}
|
@ -31,6 +31,8 @@ func Generate(parameters Parameters) (barcode.Barcode, error) {
|
||||
barcode_content, err = generate2of5(parameters)
|
||||
case Code39:
|
||||
barcode_content, err = generateCode39(parameters)
|
||||
case EAN:
|
||||
barcode_content, err = generateEAN(parameters)
|
||||
default:
|
||||
fmt.Println("Unsupported barcode type: ", parameters.Format)
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ const (
|
||||
TwoOfFive BarcodeType = "2of5"
|
||||
TwoOfFiveInterleaved BarcodeType = "2of5interleaved"
|
||||
Code39 BarcodeType = "code39"
|
||||
EAN BarcodeType = "ean"
|
||||
)
|
||||
|
||||
type ECCLevel int
|
||||
|
@ -68,21 +68,14 @@ var FormatRules = map[string]rule{
|
||||
charset: *ANY,
|
||||
divisible: 1,
|
||||
},
|
||||
/*
|
||||
"ean8": {
|
||||
minLength: 7,
|
||||
maxLength: 7,
|
||||
charset: *NUMERAL,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
"ean13": {
|
||||
minLength: 12,
|
||||
maxLength: 12,
|
||||
charset: *NUMERAL,
|
||||
divisible: 1,
|
||||
},
|
||||
*/
|
||||
"ean": {
|
||||
minLength: 7,
|
||||
maxLength: 12,
|
||||
charset: *NUMERAL,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
"pdf417": {
|
||||
minLength: 1,
|
||||
maxLength: 1100,
|
||||
|
Loading…
Reference in New Issue
Block a user