The Barcode Package is a simple yet powerful library written in Golang designed to handle barcode generation and decoding. This package provides functionalities to generate a 13-number barcode string, create barcode images, and decode barcode information from images.
- Generate 13-digit barcode strings
- Encode barcode strings into images
- Decode barcode images to retrieve information
To install the Barcode Package, use go get
:
go get github.com/myrachanto/barcode
First, import the package in your Go file:
import "github.com/myrachanto/barcode"
The GenerateBarCodeNumber
method generates a random 13-digit barcode string.
barcodeString := barcode.GenerateBarCodeNumber()
fmt.Println("Generated Barcode String:", barcodeString)
The Encode
method encodes a 13-digit barcode string into an image and saves it as a PNG file.
barcodeString := barcode.GenerateBarCodeNumber()
err := barcode.Encode(barcodeString, "barcode_image")
if err != nil {
// handle error
fmt.Println("Error:", err)
} else {
fmt.Println("Barcode image created successfully")
}
The Decode
method reads a barcode image and returns the encoded information.
decodedString, err := barcode.Decode("barcode_image")
if err != nil {
// handle error
fmt.Println("Error:", err)
} else {
fmt.Println("Decoded Barcode String:", decodedString)
}
Generates a random 13-digit barcode string.
Signature:
func GenerateBarCodeNumber() string
Encodes a 13-digit barcode string into an image and saves it as a PNG file.
Signature:
func Encode(msg, filename string) error
Parameters:
msg
(string): The 13-digit barcode string to encode.filename
(string): The name of the file (without extension) to save the barcode image.
Returns:
error
: An error if the encoding or file creation fails, otherwise nil.
Reads a barcode image and decodes it into a string.
Signature:
func Decode(filename string) (string, error)
Parameters:
filename
(string): The name of the file (without extension) to read the barcode image from.
Returns:
string
: The decoded barcode string.error
: An error if the decoding or file reading fails, otherwise nil.
Contributions are welcome! Please open an issue or submit a pull request for any changes.
- Inspired by various open-source barcode libraries.
- Special thanks to the Golang community for their support and contributions.