How to Generate a QR Code in Go

Cloudmersive
1 min readMay 14, 2021

From menus to form submissions, QR Codes have become an integral aspect of commercial sales and user interfacing, particularly as businesses have needed to transition to touchless formats. By using the following API in Go, you will be able to generate a QR code image for any kind of information storage and sharing you may need.

To perform the operation, we will call the function with the following code:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/barcode/generate/qrcode"
method := "POST"
payload := strings.NewReader("0=%3C&1=s&2=t&3=r&4=i&5=n&6=g&7=%3E")client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

The only required input (besides your API key) is the QR code text to convert into the barcode. If you need to obtain an API key, head over to the Cloudmersive website to register for a free account that will give you access to 800 calls/month across our library of APIs.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.