Giter VIP home page Giter VIP logo

go-ean-search's Introduction

go-ean-search

A Go module for EAN, GTIN and ISBN name lookup and validation using the API on https://www.ean-search.org

package main

import (
	eansearch "github.com/eansearch/go-ean-search"
	"fmt"
)

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 := "abcdefg"
	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)

	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")
        }

}

go-ean-search's People

Contributors

eansearch avatar willamowius avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

5l1v3r1 mgsousa

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.