package web import ( "encoding/base64" "net/http" qrcode "github.com/skip2/go-qrcode" ) // qrDataURI renders content as a QR code PNG and returns it as a data: URI // suitable for an , so labels need no separate image requests. func qrDataURI(content string, size int) (string, error) { png, err := qrcode.Encode(content, qrcode.Medium, size) if err != nil { return "", err } return "data:image/png;base64," + base64.StdEncoding.EncodeToString(png), nil } // requestOrigin reconstructs the scheme+host the request arrived on, for // building absolute URLs (e.g. QR codes need a full URL, not a path). func requestOrigin(r *http.Request) string { scheme := "http" if r.TLS != nil { scheme = "https" } if proto := r.Header.Get("X-Forwarded-Proto"); proto != "" { scheme = proto } return scheme + "://" + r.Host }