go get github.com/skip2/go-qrcode
https://github.com/skip2/go-qrcode
package main
import (
"fmt"
"image/color"
"github.com/skip2/go-qrcode"
)
func main() {
// 生成二维码并保存为 png
err := qrcode.WriteFile("https://www.lesscode.work", qrcode.Medium, 256, "qr.png")
fmt.Printf("err: %v\n", err)
// 生成二维码(设置背景色和二维码颜色)并保存为 png
err = qrcode.WriteColorFile(
"https://www.lesscode.work",
qrcode.Medium, 256,
color.Black,
color.White,
"qr-color.png",
)
fmt.Printf("err: %v\n", err)
}