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 github.com/skip2/go-qrcodeGenerate QR Codes with Go
Code examples using the go-qrcode library.
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)
}
}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)
}Generate QR Codes via API in Go
Call the QRCode.fun API from Go to generate styled QR codes.
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.
Native Library vs API
Compare using a Go QR code library versus the QRCode.fun API.
| Feature | Native Library | QRCode.fun API |
|---|---|---|
| Setup complexity | go get + import | Single HTTP request |
| Customization | Size, error correction | Full styling: colors, shapes, logos |
| Offline support | Yes | Requires internet |
| Maintenance | Update go.mod | Always up-to-date |
| Output formats | PNG | PNG, 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.
Start generating QR codes with Go
Use our free generator or integrate the API into your Go services.