-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
40 lines (32 loc) · 899 Bytes
/
client.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
package prometheus
// Client - A simple prometheus api client
type Client struct {
Endpoint string
// headers - A map of headers to add to the requests
headers map[string]string
}
type ClientOption func(*Client)
// NewClient - Create a new prometheus client with the given options
func NewClient(options ...ClientOption) (Client, error) {
client := Client{headers: map[string]string{}}
for _, option := range options {
option(&client)
}
// Validate the client options
if client.Endpoint == "" {
return Client{}, ErrNoEndpoint{}
}
return client, nil
}
// WithEndpoint - Set the endpoint for the client
func WithEndpoint(endpoint string) ClientOption {
return func(c *Client) {
c.Endpoint = endpoint
}
}
// WithHeaders - Set the additional headers for the client
func WithHeaders(headers map[string]string) ClientOption {
return func(c *Client) {
c.headers = headers
}
}