github.com/newrelic/newrelic-client-go@v1.1.0/pkg/users/example_users_test.go (about)

     1  package users
     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  	user, err := client.GetUser()
    20  	if err != nil {
    21  		log.Fatal("error retrieving user:", err)
    22  	}
    23  
    24  	log.Printf("User name:  %s", user.Name)
    25  	log.Printf("User email: %s", user.Email)
    26  	log.Printf("User ID:    %d", user.ID)
    27  }