-
Notifications
You must be signed in to change notification settings - Fork 6
/
example_test.go
71 lines (58 loc) · 1.74 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package footballdata_test
import (
"fmt"
"net/http"
"github.com/icedream/go-footballdata"
)
func Example() {
// Create client (optionally with auth token)
client := new(footballdata.Client).
WithToken("<insert your api token here>")
// Get list of seasons...
competitions, err := client.Competitions().Do()
if err != nil {
panic(err)
}
// ... and print them.
for _, competition := range competitions {
fmt.Println(competition.Id, competition.Caption)
}
}
func ExampleClient() {
// Create client (optionally with auth token)
client := new(footballdata.Client).
WithToken("<insert your api token here>")
// Tell it to use our API token (optional)
client.SetToken("<insert your api token here>")
// Do something with the client instance...
// Here we just fetch the listed soccer seasons on the API
competitions, err := client.Competitions().Do()
if err != nil {
panic(err)
}
for _, competition := range competitions {
fmt.Println(competition.Id, competition.Caption)
}
}
func ExampleClient_setTokenAndHttpClient() {
// Create client
client := new(footballdata.Client)
// If you have an API token, you can tell the Client instance to use it
client.SetToken("<insert your api token here>")
// The Client instance also allows you to use your own HTTP client configuration
client.SetHttpClient(&http.Client{
Transport: &http.Transport{
DisableCompression: true,
}})
}
func ExampleClient_withCustomConfiguration() {
// Create client with custom token and wrapping a custom HTTP client
client := new(footballdata.Client).
WithToken("<insert your api token here>").
WithHttpClient(&http.Client{
Transport: &http.Transport{
DisableCompression: true,
}})
// Do something with the client instance here...
_ = client
}