A QR code holds text. Phones act on some formats: they open an email draft, dial a number or join a WiFi network. Each payload type builds that text; pass the result to any render method.
text, err := qrcode.PhoneNumber{Number: "+32 9 123 45 67"}.Payload()
if err != nil {
return err
}
png, err := g.PNG(text)
Optional fields are pointers: leave them nil to omit them.
| Type | Fields | Example output |
|---|---|---|
qrcode.Email | To, Subject *string, Body *string | A draft with a prefilled subject |
qrcode.PhoneNumber | Number | tel:+32-9-123-45-67 |
qrcode.SMS | Number, Body *string | sms:+3291234567?body=See%20you%20at%208 |
qrcode.Geo | Latitude, Longitude | geo:51.05,3.72 |
qrcode.WiFi | SSID, Auth, Password *string, Hidden *bool | WIFI:T:WPA;S:Guest;P:guest-code; |
qrcode.Bitcoin | Address, Amount *string, Label *string, Message *string, ReturnURL *string | bitcoin:bc1qexample?amount=0.001 |
Invalid fields return qrcode.ErrInvalidPayload: a phone number with characters that don't belong in
one, coordinates outside ±90 and ±180, or a Bitcoin amount that isn't a plain decimal.
WiFi
password := "guest-code"
hidden := true
text, err := qrcode.WiFi{
SSID: "Guest",
Auth: qrcode.WiFiWPA,
Password: &password,
Hidden: &hidden,
}.Payload()
Auth is qrcode.WiFiWPA (WPA and WPA2), qrcode.WiFiSAE (WPA3), qrcode.WiFiWEP,
qrcode.WiFiNoPassword (an open network, stated) or qrcode.WiFiOpen (the field left out). The
package escapes ;, ,, :, \ and " in the SSID and password.
Differences from PHP
- Email uses
%20for spaces and CRLF in the message body. - Phone numbers use hyphens as visual separators where the input contains spaces.
- SMS requires a recipient and percent-escapes the
?body=query. RFC 5724 - Geo formats coordinates as decimal degrees, including very small values.
- WiFi escapes delimiters and writes an explicit boolean as
trueorfalse. Simple QrCode #333 - Bitcoin takes an exact decimal string. It percent-escapes query values and omits the question mark when all parameters are unset.