Skip to content

Pure Go implementation of the GS1 Barcode Syntax Engine – parse, validate, and generate GS1 data.

License

Notifications You must be signed in to change notification settings

adippel/gs1engine-go

Repository files navigation

Go GS1 Barcode Syntax Engine

Go Reference

A pure Go implementation for working with GS1 Data in various syntax variations as well as with GS1 Application Identifiers (AI).

Highlights:

  • ✅ Pure Go implementation, zero external dependencies
  • ✅ Parser support for the following syntax types:
    • GS1 element string syntax (e.g. (01)09526064055028(17)250521(10)ABC123(21)456DEF)
    • Barcode message format (e.g. ^01095260640550281725052110ABC123^21456DEF)
    • Barcode message scan data (e.g. ]d201095260640550281725052110ABC123{GS}21456DEF)
  • ✅ AI Registry with description of all 536 AIs (as of release 2025-01-30)
  • Go Code generator CLI to generate AI description based on the official GS1 Syntax Dictionary
  • ✅ Usable examples in examples/

⛔️ NO STABLE API yet. Not functional complete, see the following roadmap:

  • Implement GS1 data parsing support for:
    • Digital-Link URI Syntax (e.g. https://example.com/01/09526064055028)
  • Implement high-level interface to easily work with GS1 description (Flags, Specification, Attributes)
  • Implement validation support by implementing linters to validate that an AI conforms
    • to its Specification (e.g yymmdd or N6)
    • and to its attributes (e.g req and ex to define valid and invalid pairings).
  • Add GitHub workflows:
    • Unit Testing with code coverage
    • Linting
  • Add badges for build status and code coverage

Usage

Installing

Add it to your project:

go get github.com/adippel/gs1engine-go

Examples

Several examples exist in examples/ showcasing the parser:

Parsing

Several GS1 syntax formats are supported via the following functions:

  • ParseMessage: Automatically detects syntax type based on input and then uses the correct parsers.
  • ParseBarcodeMessage: Parses barcode message format and barcode scan data (e.g. ]d2..., ^...)
  • ParseElementString: Parses element string syntax (e.g (01)...(17)...)

All parser support the visual FNC1 substitutes ^ and {GS}.

🛑 Plain syntax (non-AI form) is not supported.

To start parsing, use the following:

gs1Messages := []string{
	"]d201095260640550281725052110ABC123{GS}21456DEF",
	"^01095260640550281725052110ABC123^21456DEF",
	"(01)09526064055028(17)250521(10)ABC123(21)456DEF",
}

for _, gs1Msg := range gs1Messages {
	gs1Data, _ := gs1.ParseMessage(gs1Msg)
	fmt.Println("Detected GS1 Syntax Type:", gs1Data.SyntaxType)
	fmt.Println("Message:", gs1Data.AsElementString())
}

References

The GS1 has good reference material to understand their system and approaches:

About

Pure Go implementation of the GS1 Barcode Syntax Engine – parse, validate, and generate GS1 data.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published