github.com/wtfutil/wtf@v0.43.0/modules/newrelic/client/main.go (about)

     1  /*
     2   * NewRelic API for Go
     3   *
     4   * Please see the included LICENSE file for licensing information.
     5   *
     6   * Copyright 2016 by authors and contributors.
     7   */
     8  
     9  package newrelic
    10  
    11  import (
    12  	"net/http"
    13  	"net/url"
    14  	"time"
    15  )
    16  
    17  const (
    18  	// defaultAPIURL is the default base URL for New Relic's latest API.
    19  	defaultAPIURL = "https://api.newrelic.com/v2/"
    20  	// defaultTimeout is the default timeout for the http.Client used.
    21  	defaultTimeout = 5 * time.Second
    22  )
    23  
    24  // Client provides a set of methods to interact with the New Relic API.
    25  type Client struct {
    26  	apiKey     string
    27  	httpClient *http.Client
    28  	url        *url.URL
    29  }
    30  
    31  // NewWithHTTPClient returns a new Client object for interfacing with the New
    32  // Relic API, allowing for override of the http.Client object.
    33  func NewWithHTTPClient(apiKey string, client *http.Client) *Client {
    34  	u, err := url.Parse(defaultAPIURL)
    35  	if err != nil {
    36  		panic(err)
    37  	}
    38  	return &Client{
    39  		apiKey:     apiKey,
    40  		httpClient: client,
    41  		url:        u,
    42  	}
    43  }
    44  
    45  // NewClient returns a new Client object for interfacing with the New Relic API.
    46  func NewClient(apiKey string) *Client {
    47  	return NewWithHTTPClient(apiKey, &http.Client{Timeout: defaultTimeout})
    48  }