-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexamples_test.go
67 lines (55 loc) · 1.36 KB
/
examples_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
package peeringdb
import "fmt"
func Example() {
api := NewAPI()
// Look for the organization given a name
search := make(map[string]interface{})
search["name"] = "Guillaume Mazoyer"
// Get the organization, pointer to slice returned
organizations, err := api.GetOrganization(search)
// If an error as occurred, print it
if err != nil {
fmt.Println(err)
return
}
// No organization found
if len(*organizations) < 1 {
fmt.Printf("No organization found with name '%s'\n", search["name"])
return
}
// Several organizations found
if len(*organizations) > 1 {
fmt.Printf("More than one organizations found with name '%s'\n",
search["name"])
return
}
// Get the first found organization
org := (*organizations)[0]
// Find if there are networks linked to the organization
if len(org.NetworkSet) > 0 {
// For each network
for _, networkID := range org.NetworkSet {
// Get the details and print it
network, err := api.GetNetworkByID(networkID)
if err != nil {
fmt.Println(err)
} else {
fmt.Print(network.Name)
}
}
}
// Output: Guillaume Mazoyer
}
func ExampleAPI_GetASN() {
api := NewAPI()
as201281, err := api.GetASN(201281)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("Name: %s\n", as201281.Name)
fmt.Printf("ASN: %d\n", as201281.ASN)
// Output:
// Name: Guillaume Mazoyer
// ASN: 201281
}