How to Create an EAN-13 Barcode in Go

The aptly named EAN-13 barcode is a European Article Number with 13 digits; this particular version of the barcode is the European equivalent of the North American UPC-A format. If your business is in need of an easy way to generate an EAN-13 barcode, this tutorial has a solution for you; you can use the following API in Go to create a PNG image from a specified barcode value.

Now, you will just need to input the barcode value and API key into the below code to call the API function:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := ""
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))
}

At the end of this quick process, your PNG file will be available for download. If you need to obtain an API key, head to the to register for a free account; this provides 800 calls/month across any of our APIs.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

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