barcode

A pure Go library for generating and rendering 1D and 2D barcodes, from Code128 and EAN to QR Code and PDF417.

Library
Go
vv1.1.0
1,561stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
49/100Fair
Development Activity0
Maintenance20
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture85
Code Quality78
Innovation70
Learning Curve55

barcode is a Go module for creating barcode images with no third-party dependencies. Each supported format — Aztec, Codabar, Code 128, Code 39, Code 93, DataMatrix, EAN-8, EAN-13, PDF417, QR Code, and 2 of 5 (standard and interleaved) — lives in its own subpackage with a simple Encode function, and every result satisfies Go’s standard image.Image interface so it can be written out with image/png or any other stdlib encoder.

The root package supplies the shared contract: a Barcode interface with Metadata and Content accessors, a BarcodeIntCS interface for formats that carry a checksum, ColorScheme for customizing foreground/background rendering, and Scale/ScaleWithFill helpers that resize a generated barcode to a target width and height while preserving correct 1D or 2D scaling behavior.

What You Get

  • Encoders for Aztec, Codabar, Code128, Code39, Code93, DataMatrix, EAN-8, EAN-13, PDF417, QR Code, and 2 of 5 (standard and interleaved) barcode formats
  • A shared Barcode interface satisfying image.Image, so generated codes plug directly into png, jpeg, or any other standard-library image encoder
  • Scale and ScaleWithFill helpers for resizing 1D and 2D barcodes to fit final output dimensions with a chosen fill color
  • Configurable ColorScheme presets (8/16/24/32-bit) for controlling foreground and background rendering
  • Zero third-party dependencies — the module declares no external requirements

Common Use Cases

  • Generating QR codes for URLs, Wi-Fi credentials, or payment links in server-rendered pages
  • Producing EAN-13/EAN-8 barcodes for retail product labeling systems
  • Printing Code128 or Code39 barcodes on shipping labels and inventory tags
  • Embedding PDF417 or DataMatrix codes in ID cards, boarding passes, or compliance documents

Under The Hood

Architecture The root package (barcode.go) defines the shared Barcode, BarcodeIntCS, and BarcodeColor interfaces plus the Metadata struct that every format subpackage’s encoder must satisfy. scaledbarcode.go implements Scale/ScaleWithFill through a decorator pattern: a scaledBarcode struct wraps the original barcode with a coordinate-remapping wrapFunc, and intCSscaledBC embeds scaledBarcode to preserve access to the checksum interface after wrapping. Each barcode format (aztec, codabar, code128, code39, code93, datamatrix, ean, pdf417, qr, twooffive) is an independent subpackage whose Encode function returns a type satisfying the root Barcode contract, keeping formats fully decoupled from one another and from the shared scaling/color logic; a shared utils subpackage provides bit-level helpers used by several encoders. Adding a new format requires no changes to the root package, and replacing the core interface only touches each subpackage’s encoder struct.

Tech Stack Pure Go standard library only — go.mod declares the module with no require directives. The library relies on image, image/color, and math from the stdlib for compositing and scaling calculations, plus errors/fmt for explicit error construction. Build and test tooling is stock go build/go test; CI runs via GitHub Actions across a matrix of supported Go versions, with a separate lint workflow running golangci-lint (errcheck, govet, ineffassign, staticcheck, unused) alongside gofmt/goimports formatting checks.

Code Quality About a third of the module’s Go files are test files, concentrated on the most algorithmic packages — the qr subpackage alone has dedicated tests for its alphanumeric, automatic, blocks, encoder, error-correction, numeric, and unicode logic. Error handling favors explicit returned errors (errors.New, fmt.Errorf) over panics for invalid dimensions or unsupported formats. Naming follows standard Go convention, and the Barcode/BarcodeIntCS/BarcodeColor interfaces enforce compile-time contracts in place of runtime type assertions in most call paths. CI enforces golangci-lint plus formatting checks on every push and pull request.

What Makes It Unique The library’s main design choice is making every generated barcode satisfy image.Image directly, so callers get PNG/JPEG/GIF export for free via the standard library instead of a bespoke writer API — a comparatively low-friction integration point relative to barcode libraries that ship their own rendering or export functions. It implements well-established barcode standards rather than inventing new ones, so its value is ergonomic consistency across many formats rather than algorithmic novelty.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search