https://github.com/eansearch/go-ean-search
A Go module for EAN, GTIN and ISBN name lookup and validation using the API on https://www.ean-search.org
https://github.com/eansearch/go-ean-search
barcode ean ean13 gtin gtin-codes isbn isbn-13 upc
Last synced: 9 months ago
JSON representation
A Go module for EAN, GTIN and ISBN name lookup and validation using the API on https://www.ean-search.org
- Host: GitHub
- URL: https://github.com/eansearch/go-ean-search
- Owner: eansearch
- License: mit
- Created: 2021-03-01T15:15:38.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-02-23T10:03:03.000Z (over 1 year ago)
- Last Synced: 2025-04-08T05:36:47.194Z (about 1 year ago)
- Topics: barcode, ean, ean13, gtin, gtin-codes, isbn, isbn-13, upc
- Language: Go
- Homepage: https://www.ean-search.org/ean-database-api.html
- Size: 32.2 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-ean-search
A Go module for EAN, GTIN and ISBN name lookup and validation using the API on https://www.ean-search.org
```go
package main
import (
eansearch "github.com/eansearch/go-ean-search"
"fmt"
"os"
)
func printProduct(p eansearch.Product) {
fmt.Println("EAN:\t", p.Ean)
fmt.Println("\t Name:", p.Name)
fmt.Println("\t CategoryID:", p.CategoryID)
fmt.Println("\t CategoryName:", p.CategoryName)
fmt.Println("\t IssuingCountry:", p.IssuingCountry)
}
func main() {
var products []eansearch.Product
var more bool
var err error
var country string
// get an API token at https://www.ean-search.org/ean-database-api.html
token := os.Getenv("EAN_SEARCH_API_TOKEN");
eansearch.SetToken(token)
products, err = eansearch.BarcodeLookup("5099750442227", eansearch.English)
if err != nil {
fmt.Println(err)
} else if len(products) == 0 {
fmt.Println("No results found")
} else {
printProduct(products[0])
}
products, err = eansearch.ISBNLookup("1119578884")
if err != nil {
fmt.Println(err)
} else if len(products) == 0 {
fmt.Println("No results found")
} else {
printProduct(products[0])
}
products, more, err = eansearch.ProductSearch("esprit pullover", 0, eansearch.English)
// products, more, err = eansearch.SimilarProductSearch("esprit whateverelsenotfound pullover", 0, eansearch.English)
if err != nil {
fmt.Println(err)
} else if len(products) == 0 {
fmt.Println("No results found")
} else {
for _, p := range products {
printProduct(p)
}
if more {
fmt.Println("More results available")
}
}
products, more, err = eansearch.BarcodePrefixSearch("40620999", 0, eansearch.AnyLanguage)
if err != nil {
fmt.Println(err)
} else if len(products) == 0 {
fmt.Println("No results found")
} else {
for _, p := range products {
printProduct(p)
}
if more {
fmt.Println("More results available")
}
}
ean := "5099750442227"
country, err = eansearch.IssuingCountryLookup(ean)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("EAN %s was issued in %s\n", ean, country)
}
ean = "5099750442228"
valid, err := eansearch.VerifyChecksum(ean)
if err != nil {
fmt.Println(err)
} else {
if (valid) {
fmt.Printf("EAN %s is VALID\n", ean)
} else {
fmt.Printf("EAN %s is INVALID\n", ean)
}
}
ean = "5099750442227"
image, err := eansearch.BarcodeImage(ean)
if err != nil {
fmt.Println(err)
} else {
//fmt.Print("Content-Type: image/png\n\n")
//fmt.Printf("%s", image)
_ = image
fmt.Println("Barcode image received")
}
}