Implement creation
This commit is contained in:
28
generation/aztec.go
Normal file
28
generation/aztec.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/aztec"
|
||||
)
|
||||
|
||||
func generateAztec(parameters Parameters) (barcode.Barcode, error) {
|
||||
var level uint8
|
||||
switch parameters.ECCLevel {
|
||||
case 1:
|
||||
level = 7
|
||||
case 2:
|
||||
level = 15
|
||||
case 3:
|
||||
level = 25
|
||||
case 4:
|
||||
level = 30
|
||||
}
|
||||
aztecCode, err := aztec.Encode([]byte(parameters.Content), int(level), 0)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating Barcode", err)
|
||||
}
|
||||
|
||||
return aztecCode, err
|
||||
}
|
||||
16
generation/codabar.go
Normal file
16
generation/codabar.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/codabar"
|
||||
)
|
||||
|
||||
func generateCodabar(parameters Parameters) (barcode.Barcode, error) {
|
||||
codabar, err := codabar.Encode(parameters.Content)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating Barcode", err)
|
||||
}
|
||||
return codabar, err
|
||||
}
|
||||
16
generation/code128.go
Normal file
16
generation/code128.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/code128"
|
||||
)
|
||||
|
||||
func generateCode128(parameters Parameters) (barcode.Barcode, error) {
|
||||
barcode, err := code128.EncodeWithoutChecksum(parameters.Content)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating Barcode", err)
|
||||
}
|
||||
return barcode, err
|
||||
}
|
||||
16
generation/code93.go
Normal file
16
generation/code93.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/code93"
|
||||
)
|
||||
|
||||
func generateCode93(parameters Parameters) (barcode.Barcode, error) {
|
||||
barcode, err := code93.Encode(parameters.Content, true, true)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating Barcode", err)
|
||||
}
|
||||
return barcode, err
|
||||
}
|
||||
16
generation/datamatrix.go
Normal file
16
generation/datamatrix.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/datamatrix"
|
||||
)
|
||||
|
||||
func generateDatamatrix(parameters Parameters) (barcode.Barcode, error) {
|
||||
barcode, err := datamatrix.Encode(parameters.Content)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating Barcode", err)
|
||||
}
|
||||
return barcode, err
|
||||
}
|
||||
31
generation/generate.go
Normal file
31
generation/generate.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
)
|
||||
|
||||
func Generate(parameters Parameters) (barcode.Barcode, error) {
|
||||
var barcode_content barcode.Barcode
|
||||
var err error
|
||||
|
||||
switch parameters.Format {
|
||||
case Aztec:
|
||||
barcode_content, err = generateAztec(parameters)
|
||||
case Codabar:
|
||||
barcode_content, err = generateCodabar(parameters)
|
||||
case Code93:
|
||||
barcode_content, err = generateCode93(parameters)
|
||||
case Code128:
|
||||
barcode_content, err = generateCode128(parameters)
|
||||
case QR:
|
||||
barcode_content, err = generateQr(parameters)
|
||||
case Datamatrix:
|
||||
barcode_content, err = generateDatamatrix(parameters)
|
||||
default:
|
||||
fmt.Println("Unsupported barcode type: ", parameters.Format)
|
||||
}
|
||||
|
||||
return barcode_content, err
|
||||
}
|
||||
28
generation/qr.go
Normal file
28
generation/qr.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/qr"
|
||||
)
|
||||
|
||||
func generateQr(parameters Parameters) (barcode.Barcode, error) {
|
||||
var level qr.ErrorCorrectionLevel
|
||||
switch parameters.ECCLevel {
|
||||
case 1:
|
||||
level = qr.L
|
||||
case 2:
|
||||
level = qr.M
|
||||
case 3:
|
||||
level = qr.Q
|
||||
case 4:
|
||||
level = qr.H
|
||||
}
|
||||
qrCode, err := qr.Encode(parameters.Content, level, qr.Auto)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating Barcode", err)
|
||||
}
|
||||
|
||||
return qrCode, err
|
||||
}
|
||||
29
generation/types.go
Normal file
29
generation/types.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package generation
|
||||
|
||||
type BarcodeType string
|
||||
|
||||
const (
|
||||
Aztec BarcodeType = "aztec"
|
||||
Codabar BarcodeType = "codabar"
|
||||
Code93 BarcodeType = "code93"
|
||||
Code128 BarcodeType = "code128"
|
||||
QR BarcodeType = "qr"
|
||||
Datamatrix BarcodeType = "datamatrix"
|
||||
)
|
||||
|
||||
type ECCLevel int
|
||||
|
||||
const (
|
||||
Low ECCLevel = 1
|
||||
Med ECCLevel = 2
|
||||
High ECCLevel = 3
|
||||
Max ECCLevel = 4
|
||||
)
|
||||
|
||||
type Parameters struct {
|
||||
Format BarcodeType
|
||||
ECCLevel ECCLevel
|
||||
Content string
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user