Read label images
Pass a PNG, JPEG, WebP or GIF label file path to scanner.Scan(). A Code 128 label encoding STOCK-4827 returns that exact string.
pkg.go.dev
Zero cgo
1D + 2D
MIT
Decode 1D and 2D barcode files inside Go services using only the standard library, context cancellation and intact leading zeros.
Pass a PNG, JPEG, WebP or GIF label file path to scanner.Scan(). A Code 128 label encoding STOCK-4827 returns that exact string.
Compiles cleanly with CGO_ENABLED=0 and invokes qrscan directly without a shell so uploaded filenames cannot inject commands.
Returns identifiers as Go strings (never converting them to integers) so UPC-A and EAN-13 leading zeros always remain intact.
Install the Go module alongside the qrscan CLI, then extract barcode strings and symbologies with context cancellation.
Requires Go 1.24 or newer and the Go module on pkg.go.dev. Install the matching Barcode Scanner CLI binary separately via Homebrew, Scoop, Cargo, Debian/RPM, AUR, AppImage, GitHub Releases or container image.
The Go module bundles no decoder and never downloads qrscan at runtime. Keep the module and qrscan binary aligned on the same release line.
go get github.com/qrcode-ai-com/qrcode-barcode-scanner-go@v0.12.2
CGO_ENABLED=0 works seamlessly because the Go adapter contains zero C code.
Provide an explicit path to qrscan.New("/path/to/qrscan") whenever qrscan sits outside PATH.
Invoke scanner.Scan with a context, file path, profile and budget, then filter for the barcode symbologies your workflow needs and return exact strings.
To verify with a known label, create a Code 128 barcode with Barcode Generator encoding STOCK-4827 and scan the exported PNG.
package main
import (
"context"
"fmt"
qrscan "github.com/qrcode-ai-com/qrcode-barcode-scanner-go"
)
type BarcodeReading struct{ Symbology, Text string }
func readBarcodes(ctx context.Context, path string) ([]BarcodeReading, error) {
scanner := qrscan.New("")
report, err := scanner.Scan(ctx, path, qrscan.Frame, qrscan.ProfileBudget)
if err != nil {
return nil, err
}
if !report.Complete {
return nil, fmt.Errorf("scan budget cut before completion")
}
var out []BarcodeReading
for _, d := range report.Detections {
if d.Symbology != "qr_code" && d.Symbology != "micro_qr_code" && d.Symbology != "rectangular_micro_qr_code" {
out = append(out, BarcodeReading{Symbology: d.Symbology, Text: d.Text})
}
}
return out, nil
}
Start with qrscan.Frame for decode-only runs, or move to qrscan.Full and qrscan.Unbounded for worn or tricky label photos.
Inspect report.JSON directly whenever you need parsed GS1 payloads, occurrences or measured geometry.
For a Code 128 label encoding STOCK-4827, readBarcodes returns BarcodeReading{Symbology: "code128", Text: "STOCK-4827"}. A UPC-A code such as 012345678905 keeps its leading zero intact as a Go string.
A blank image or QR-only file returns an empty slice and nil error. Handle qrscan.ErrBinaryNotFound, *qrscan.UnsupportedVersionError and *qrscan.ScanError (EngineCode such as QRS-001).
Sixteen barcode formats. Since the adapter forwards the qrscan report verbatim, it decodes EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar, ITF, Telepen, GS1 DataBar, GS1 DataBar Expanded, Data Matrix, PDF417, Aztec and MaxiCode (ISBN maps to ean13, GS1-128 to code128, ITF-14 to itf).
Process model and input files. Each Scan() call spawns qrscan from an explicit argument slice without a shell (safe for arbitrary filenames). Write in-memory uploads to a temporary file first; this fits API handlers and batch jobs better than tight frame loops.
Exact strings and licence. Identifiers stay as Go strings so leading zeros never vanish, while product lookups remain in your own database. Adapter source is MIT-licensed; read the Go adapter README and Go module repository.
Official module guides, ScanReport schema specification and licensing notices.
cgo, qrscan prerequisite, barcode formats, leading zeros, error handling and licensing.
It is QR Code AI’s open-source MIT-licensed Go module (github.com/qrcode-ai-com/qrcode-barcode-scanner-go) that drives the separately installed qrscan CLI using only Go’s standard library and returns decoded barcode strings and symbologies verbatim.
No. It requires Go 1.24 or later and compiles cleanly with CGO_ENABLED=0. You only need a matching qrscan binary installed on your host or inside your container image.
It returns everything decoded by the installed qrscan engine: 16 barcode formats (EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar, ITF, Telepen, GS1 DataBar, GS1 DataBar Expanded, Data Matrix, PDF417, Aztec and MaxiCode) plus QR Code, Micro QR and rMQR.
Yes to keeping leading zeros, no to fetching product names. The adapter preserves every decoded identifier as a Go string rather than converting it to an integer, so UPC-A and EAN-13 leading zeros stay intact. Query your own catalogue or inventory database separately.
Earlier wazero WebAssembly experiments produced identical reports but ran roughly twenty times slower on photo-sized inputs. Calling native qrscan keeps native decoding speed without cgo, fitting HTTP handlers and batch jobs well (for tight in-process loops, use Rust, Node.js, Python or .NET).
A blank image returns report.Found() == false with err == nil (verify report.Complete is true). Hard failures surface as ErrBinaryNotFound, *UnsupportedVersionError, *ScanError (carrying EngineCode such as QRS-001) or the context error.
Yes. Both the Go adapter and the qrscan CLI execute 100% locally with zero network requests, no QR Code AI account, no API key and no creation credits.
Yes. Current releases of the Go adapter and the qrscan engine ship under the MIT licence for commercial and proprietary applications while keeping copyright and licence notices intact (see LICENSING.md). SDK usage is independent of QR Code AI’s paid creation plans and seven-day Premium trial.