forked from TheQuestionru/newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (42 loc) · 1.14 KB
/
main.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
/*
* NewRelic API for Go
*
* Please see the included LICENSE file for licensing information.
*
* Copyright 2016 by authors and contributors.
*/
package newrelic
import (
"net/http"
"net/url"
"time"
)
const (
// defaultAPIURL is the default base URL for New Relic's latest API.
defaultAPIURL = "https://api.newrelic.com/v2/"
// defaultTimeout is the default timeout for the http.Client used.
defaultTimeout = 5 * time.Second
)
// Client provides a set of methods to interact with the New Relic API.
type Client struct {
apiKey string
httpClient *http.Client
url *url.URL
}
// NewWithHTTPClient returns a new Client object for interfacing with the New
// Relic API, allowing for override of the http.Client object.
func NewWithHTTPClient(apiKey string, client *http.Client) *Client {
u, err := url.Parse(defaultAPIURL)
if err != nil {
panic(err)
}
return &Client{
apiKey: apiKey,
httpClient: client,
url: u,
}
}
// NewClient returns a new Client object for interfacing with the New Relic API.
func NewClient(apiKey string) *Client {
return NewWithHTTPClient(apiKey, &http.Client{Timeout: defaultTimeout})
}