github.com/newrelic/newrelic-client-go@v1.1.0/pkg/accounts/example_accounts_test.go (about)

     1  package accounts
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  
     7  	"github.com/newrelic/newrelic-client-go/pkg/config"
     8  )
     9  
    10  func Example_accounts() {
    11  	// Initialize the client configuration.  A Personal API key is required to
    12  	// communicate with the backend API.
    13  	cfg := config.New()
    14  	cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY")
    15  
    16  	// Initialize the client.
    17  	client := New(cfg)
    18  
    19  	// List the accounts this user is authorized to view.
    20  	params := ListAccountsParams{
    21  		Scope: &RegionScopeTypes.GLOBAL,
    22  	}
    23  
    24  	accounts, err := client.ListAccounts(params)
    25  	if err != nil {
    26  		log.Fatal("error retrieving accounts:", err)
    27  	}
    28  
    29  	log.Printf("accounts count: %d", len(accounts))
    30  }