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 in Go services with standard library only, 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 with CGO_ENABLED=0 and starts qrscan directly without a shell so uploaded filenames cannot inject commands.
Forwards identifiers as Go strings (never converting them to integers) so UPC-A and EAN-13 leading zeros always survive.
Install the Go module and the qrscan CLI, then extract barcode strings and symbologies with context cancellation.
Requires Go 1.24 or later 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 embeds no decoder and never downloads qrscan at runtime. Keep the module and qrscan binary on the same release line.
go get github.com/qrcode-ai-com/qrcode-barcode-scanner-go@v0.12.2
CGO_ENABLED=0 is fully supported because the Go adapter contains zero C code.
Pass an explicit path to qrscan.New("/path/to/qrscan") when qrscan lives outside PATH.
Call scanner.Scan with a context, file path, profile and budget, then keep the barcode symbologies your workflow expects and return exact strings.
To test with a known reference, 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
}
Use qrscan.Frame for decoding only, or switch to qrscan.Full and qrscan.Unbounded for difficult label photos.
Read report.JSON directly when 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 label 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. Check qrscan.ErrBinaryNotFound, *qrscan.UnsupportedVersionError and *qrscan.ScanError (EngineCode such as QRS-001).
Sixteen barcode formats. Because the adapter forwards the qrscan report verbatim, it reads 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() spawns qrscan from an argument slice without a shell (safe for arbitrary filenames). Write in-memory uploads to a temporary file first; this fits requests and batch jobs rather than tight frame loops.
Exact strings and licence. Identifiers stay strings so leading zeros never drop, and product lookups remain in your own database. Adapter source is MIT-licensed; see the Go adapter README and Go module repository.
Official package documentation, ScanReport specification and licensing references.
cgo, qrscan prerequisite, formats, leading zeros, errors and licensing.
It is QR Code AI’s open-source MIT 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 unchanged.
No. It requires Go 1.24 or later and builds cleanly with CGO_ENABLED=0 without cgo or a C toolchain. You only need a compatible qrscan binary installed on your host or container.
It returns whatever the installed qrscan engine decodes: 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 leading zeros, no to product lookups. The adapter forwards identifiers as Go strings instead of converting them into integers, so UPC-A and EAN-13 leading zeros stay intact. Query your own catalogue or stock database separately.
Earlier wazero WebAssembly tests produced identical reports but ran roughly twenty times slower on photo-sized images. Invoking native qrscan keeps native speed without cgo, fitting request handlers and batch jobs (for tight loops, use Rust, Node.js, Python or .NET).
A blank image returns report.Found() == false with err == nil (verify report.Complete is true). Errors surface as ErrBinaryNotFound, *UnsupportedVersionError, *ScanError (with EngineCode such as QRS-001) or the context error.
No. Both the Go adapter and qrscan run 100% locally with no network requests, no QR Code AI account, no API key and no creation credits.
Yes. Current releases of the Go adapter and qrscan engine are MIT-licensed for commercial and proprietary software while keeping copyright and licence notices (see LICENSING.md). SDK use is separate from QR Code AI’s paid creation plans and seven-day Premium trial.