forked from chiefy/go-statuspage-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
37 lines (33 loc) · 944 Bytes
/
Copy pathclient.go
File metadata and controls
37 lines (33 loc) · 944 Bytes
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
package statuspage
import (
"fmt"
"net/http"
"net/url"
"time"
)
// DefaultAPIURL should be the current URL prefix as described in the docs:
// https://doers.statuspage.io/api/basics/
const DefaultAPIURL = "https://api.statuspage.io/v1/pages/"
// Client contains the information needed to find and consume the StatusPage API
type Client struct {
apiKey string
pageID string
httpClient *http.Client
url *url.URL
}
// NewClient creates a new Client from a StatusPage API key and page ID
// See https://doers.statuspage.io/api/authentication/ on how to obtain
// an API key.
func NewClient(apiKey, pageID string) (*Client, error) {
u, err := url.Parse(DefaultAPIURL + pageID + "/")
if err != nil {
return nil, fmt.Errorf("url error parsing (%s): %s", pageID, err)
}
c := Client{
apiKey: apiKey,
pageID: pageID,
httpClient: &http.Client{Timeout: 5 * time.Second},
url: u,
}
return &c, nil
}