Skip to content

gmazoyer/peeringdb

Repository files navigation

PeeringDB API - Go package

Go Reference Go Report Card

This is a Go package that allows developer to interact with the PeeringDB API in the easiest way possible. There are no binaries provided with this package. It can only be used as a library.

Installation

Install the library package with go get github.com/gmazoyer/peeringdb.

Example

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/gmazoyer/peeringdb"
)

func main() {
	// Create an API client (optionally with an API key)
	api := peeringdb.NewAPI(
		peeringdb.WithAPIKey("your-api-key"),
	)
	ctx := context.Background()

	// Look up a network by its ASN
	network, err := api.GetASN(ctx, 201281)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Network: %s (AS%d)\n", network.Name, network.ASN)

	// List all facilities linked to this network
	for _, netfacID := range network.NetworkFacilitySet {
		netfac, err := api.GetNetworkFacilityByID(ctx, netfacID)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("  Facility: %s (%s, %s)\n", netfac.Name, netfac.City, netfac.Country)
	}
}

More examples are available in the package documentation.

You can also find a real life example with the PeeringDB synchronization tool.

About

PeeringDB API package for Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages