-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
example_test.go
36 lines (30 loc) · 974 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright © 2019 OpenFoodFacts. All rights reserved.
// Use of this source code is governed by the MIT license which can be found in the LICENSE.txt file.
package openfoodfacts
import (
"fmt"
"time"
)
// You can use the Client.Product method to retrieve a Product by barcode.
func ExampleClient_Product() {
api := NewClient("world", "", "")
product, err := api.Product("5201051001076")
if err != nil {
fmt.Printf("%+v\n", product)
}
}
// This will enable test mode and connect you to the sandbox server.
func ExampleClient_Sandbox() {
api := NewClient("world", "", "")
api.Sandbox() // Enable test mode
}
// This will set a timeout for the http client
func ExampleClient_Timeout() {
api := NewClient("world", "", "")
api.Timeout(10 * time.Second) // Set http client timeout
}
// Create a Client to retrieve and modify database items.
// Client interacts with the official HTTP API from openfoodfacts.org.
func Example() {
NewClient("world", "", "")
}