go-qrcode
Pure Go library for encoding QR Codes as PNG images or ASCII art, with zero external dependencies.
Repository Health
Technical Analysis
go-qrcode is a dependency-free Go package that implements a QR Code encoder from scratch, following the ISO/IEC 18004:2006 specification. It exposes a small handful of top-level functions — Encode, WriteFile, and WriteColorFile — that turn arbitrary text or binary content into a QR Code and hand back either raw PNG bytes or a file written directly to disk, with a choice of four error-recovery levels (Low, Medium, High, Highest) trading physical code size for damage tolerance.
Under the API surface sits a full from-scratch implementation: a data-segmentation encoder that picks the most compact mix of numeric, alphanumeric, and byte modes, a Reed-Solomon error-correction layer built on Galois-field arithmetic, and a symbol/mask-pattern builder that lays out and optimizes the final matrix. The library also ships a qrcode CLI binary in its qrcode/ subdirectory for generating codes straight from the command line, and supports rendering as colored PNGs, variable-size images, or plain ASCII/text-art for terminal output.
What You Get
- One-line functions to encode a string into a PNG QR Code, in memory or written straight to a file
- Four selectable error-recovery levels (Low, Medium, High, Highest) to trade code density for damage resistance
- Custom foreground/background color support via WriteColorFile for branded or inverted QR Codes
- Variable-size image output (negative size values control per-module pixel width instead of a fixed overall size)
- A bundled
qrcodeCLI tool for generating codes from the terminal, including a text-art rendering mode
Common Use Cases
- Embedding scannable QR Codes for URLs, Wi-Fi credentials, or contact details into a Go web service’s generated pages or PDFs
- Generating one-off QR Codes from the command line for signage, packaging, or documentation without writing any code
- Producing ticket, badge, or inventory-tag QR Codes as part of a batch-processing pipeline
- Rendering ASCII/text-art QR Codes directly in terminal output for CLI tools and debugging
Under The Hood
Architecture
go-qrcode is organized as a small, layered pipeline rather than a single monolith: the root qrcode package exposes the public API (New, Encode, WriteFile, PNG, Image, ToString in qrcode.go), which delegates to encoder.go for data-segmentation logic (choosing and coalescing numeric/alphanumeric/byte encoding modes per segment), to regular_symbol.go and symbol.go for laying out the QR matrix and selecting a mask pattern, and to version.go for the large per-version capacity and error-correction lookup tables mandated by the spec. Two independent subpackages, bitset and reedsolomon, isolate low-level primitives — a bit-level buffer abstraction and Galois-field polynomial arithmetic for Reed-Solomon error correction — so the core algorithm stays composed of narrow, single-purpose files; changing the masking heuristic or the segment-coalescing logic touches only its own file, and a companion qrcode/main.go CLI simply calls the public package API.
Tech Stack
The library has zero external dependencies — go.mod declares no require entries — and is built entirely on the Go standard library: image, image/color, and image/png for raster output, io/os for file writing, and flag for the bundled CLI’s argument parsing. It targets Go 1.13, builds with the standard go build/go test toolchain, and its only CI configuration is a now-defunct .travis.yml running go test -v ./... against Go 1.7 — there is no modern GitHub Actions workflow in the repo.
Code Quality
Each core source file has a matching _test.go counterpart (encoder, symbol, regular_symbol, version, bitset, reed-solomon, and an example test), giving broad coverage of the encoding, matrix-construction, and error-correction paths, including a QR decode test used to round-trip verify generated codes. Error handling is idiomatic Go throughout — public functions return error values rather than panicking, and no panic/log.Fatal calls were found in the library code itself. Naming follows standard Go conventions (unexported camelCase internals, exported PascalCase API), but the project’s only CI definition targets a Go version and CI provider (Travis) that predate the repo’s more recent commits, so automated verification is effectively stale.
API Design
The public surface is deliberately minimal — three top-level functions cover the vast majority of use cases, with New plus struct fields (DisableBorder, ForegroundColor, BackgroundColor) available for anyone who needs finer control. Godoc-style comments on every exported function spell out size and recovery-level semantics up front, and example_test.go demonstrates the common calls directly, so getting a working QR Code out of the library requires very little boilerplate.
Used by 3 apps in this directory
1Panel
Devops · Hosting Control Panel · Monitoring
The only open-source VPS control panel with native AI agent runtime — deploy websites, Docker stacks, and local LLMs from one web interface.
cli
Developer Tools · Team Chat
The official Lark/Feishu CLI tool built for both humans and AI agents, delivering 200+ commands and 26 AI agent skills across 18 business domains from messaging and calendar to docs, sheets, and approvals.
Netmaker
Automation · Security
Automate secure WireGuard mesh networks from homelab to enterprise scale without manual configuration.