How to Generate a UPC-E Barcode in Go

Cloudmersive
2 min readJun 11, 2021

--

While the EAN barcode format is widely used in Europe, the most commonly used format in North America is the UPC format. UPC-A is the full 12-digit version, and UPC-E is the condensed 6-digit version, with a seventh check digit included. By utilizing the following API in Go, you will be able to automatically generate a UPC-E barcode image. It is important to note that a UPC-E barcode should primarily only be used for an item with packaging too small to contain a full UPC-A barcode.

To call the API function, simply add your barcode value and API key to the below example code:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/barcode/generate/upc-e"
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))
}

This will instantly return a downloadable PNG image of your 1D UPC-E barcode. To obtain an API key, you can visit the Cloudmersive website and register for a free account; this will provide 800 calls/month across our library of APIs.

--

--

Cloudmersive

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