eansearch

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 7 Imported by: 0

README

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

    // get an API token at https://www.ean-search.org/ean-database-api.html
    token := "abcdef"
    eansearch.SetToken(token)

    ean := "5099750442227"

    products, err = eansearch.BarcodeLookup(ean, eansearch.English)

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

    products, more, err = eansearch.CategorySearch(45, "thriller", 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")
        }
    }

}

Documentation

Overview

Package eansearch is a Go module for EAN, GTIN and ISBN name lookup and validation

Index

Constants

View Source
const AnyLanguage uint = 99
View Source
const Danish uint = 2
View Source
const Dutch uint = 10
View Source
const English uint = 1
View Source
const Finish uint = 5
View Source
const French uint = 6
View Source
const German uint = 3
View Source
const Italian uint = 8
View Source
const Norwegian uint = 11
View Source
const Polish uint = 12
View Source
const Portuguese uint = 13
View Source
const Spanish uint = 4
View Source
const Swedish uint = 15

Variables

This section is empty.

Functions

func SetToken

func SetToken(t string) error

SetToken initialises the API with the token, you can apply for at https://www.ean-search.org/ean-database-api.html

Types

type Product

type Product struct {
	Ean            string
	Name           string
	CategoryID     uint `json:",string"`
	CategoryName   string
	IssuingCountry string
}

Product holds datasets returned by the API

func BarcodeLookup

func BarcodeLookup(ean string, lang uint) ([]Product, error)

BarcodeLookup searches for a single EAN code

func BarcodePrefixSearch

func BarcodePrefixSearch(prefix string, page uint, lang uint) ([]Product, bool, error)

BarcodePrefixSearch find all EANs strating with a certain prefix

func ProductSearch

func ProductSearch(name string, page uint, lang uint) ([]Product, bool, error)

ProductSearch searches for products by name

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL