Skip to content

Instantly share code, notes, and snippets.

@r10r
Created February 16, 2021 11:13
Show Gist options
  • Save r10r/a2450c2aeb8858edd60eb963803b8f71 to your computer and use it in GitHub Desktop.
Save r10r/a2450c2aeb8858edd60eb963803b8f71 to your computer and use it in GitHub Desktop.
Generate simple QRCode
package main
import (
qrcode "github.com/skip2/go-qrcode"
"io/ioutil"
"os"
)
func main() {
/*
The maximum capacity of a QR Code varies according to the content encoded and the error recovery level. The maximum capacity is 2,953 bytes, 4,296 alphanumeric characters, 7,089 numeric digits, or a combination of these.
*/
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
var png []byte
png, err = qrcode.Encode(string(data), qrcode.Medium, 256)
if err != nil {
panic(err)
}
_, err = os.Stdout.Write(png)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment