Go QR Code Library

Generate QR Codes with Go

Go is ideal for high-performance QR code generation in microservices and CLI tools. Use the go-qrcode library for local generation or the QRCode.fun API for styled outputs.

Installation

Install the Go QR code library using go get.

go get
go get github.com/skip2/go-qrcode

Generate QR Codes with Go

Code examples using the go-qrcode library.

Basic QR Code Generation
package main

import "github.com/skip2/go-qrcode"

func main() {
    err := qrcode.WriteFile("https://qrcode.fun", qrcode.Medium, 256, "qrcode.png")
    if err != nil {
        panic(err)
    }
}
QR Code as Bytes (HTTP Handler)
package main

import (
    "net/http"
    "github.com/skip2/go-qrcode"
)

func qrHandler(w http.ResponseWriter, r *http.Request) {
    data := r.URL.Query().Get("data")
    if data == "" {
        data = "https://qrcode.fun"
    }

    png, err := qrcode.Encode(data, qrcode.Medium, 256)
    if err != nil {
        http.Error(w, err.Error(), 500)
        return
    }

    w.Header().Set("Content-Type", "image/png")
    w.Write(png)
}

func main() {
    http.HandleFunc("/qr", qrHandler)
    http.ListenAndServe(":8080", nil)
}
QRCode.fun API

Generate QR Codes via API in Go

Call the QRCode.fun API from Go to generate styled QR codes.

Go API Integration
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    payload := map[string]interface{}{
        "data":   "https://qrcode.fun",
        "width":  300,
        "height": 300,
        "type":   "png",
        "margin": 10,
        "dotsOptions": map[string]string{
            "color": "#1A2B3C",
            "type":  "rounded",
        },
        "cornersSquareOptions": map[string]string{
            "color": "#8564C3",
            "type":  "extra-rounded",
        },
        "backgroundOptions": map[string]string{
            "color": "#FFFFFF",
        },
    }

    body, _ := json.Marshal(payload)
    resp, err := http.Post(
        "https://qrcode.fun/api/generate-qr-styled",
        "application/json",
        bytes.NewBuffer(body),
    )
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    data, _ := io.ReadAll(resp.Body)
    fmt.Println(string(data[:100]))
}

Live QR Code Preview

Try generating a QR code with Go right now.

QR preview

Native Library vs API

Compare using a Go QR code library versus the QRCode.fun API.

FeatureNative LibraryQRCode.fun API
Setup complexitygo get + importSingle HTTP request
CustomizationSize, error correctionFull styling: colors, shapes, logos
Offline supportYesRequires internet
MaintenanceUpdate go.modAlways up-to-date
Output formatsPNGPNG, SVG

Go QR Code Use Cases

Common scenarios for QR codes in Go applications.

Microservices

Generate QR codes in Go microservices for API responses, webhooks, and event-driven architectures.

CLI Tools

Build command-line utilities that generate QR codes for Wi-Fi sharing, URL shortening, or terminal display.

Cloud Functions

Deploy QR generation as serverless functions on AWS Lambda or Google Cloud Functions using Go.

DevOps & Infrastructure

Generate QR codes for deployment URLs, monitoring dashboards, and configuration endpoints.

Frequently Asked Questions

Common questions about generating QR codes with Go.

skip2/go-qrcode is the most popular Go QR code library. It generates PNG images and supports configurable size and error correction levels.

Start generating QR codes with Go

Use our free generator or integrate the API into your Go services.