forked from gmazoyer/peeringdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
62 lines (51 loc) · 1.31 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
package peeringdb
import "fmt"
func Example() {
api := NewAPI()
// Look for the organization given a name
search := make(map[string]interface{})
search["name"] = "LuxNetwork S.A."
// 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: LuxNetwork S.A.
}
func ExampleAPI_GetASN() {
api := NewAPI()
as29467 := api.GetASN(29467)
fmt.Printf("Name: %s\n", as29467.Name)
fmt.Printf("AS number: %d\n", as29467.ASN)
// Output:
// Name: LuxNetwork S.A.
// AS number: 29467
}