-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
39 lines (33 loc) · 1.17 KB
/
session.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
package akamai
import (
"net/http"
)
// Session is an API session that allows interaction with the SolarSystems Akamai API.
// Sessions should be created with one of the utility functions, like NewSession.
//
// Callers should re-use the same Session as much as possible, even across different tasks.
// This will provide the best performance.
type Session struct {
// The API key to use when authorizing with the SolarSystems API.
apiKey string
// The http.Client to use when making API requests.
client *http.Client
}
// NewSessionWithClient creates a new Session with the given API key and HTTP client.
// The given client is responsible for making requests to the SolarSystems API.
//
// NewSessionWithClient panics if client == nil.
func NewSessionWithClient(apiKey string, client *http.Client) Session {
if client == nil {
panic("akamai-sdk-go: nil client passed to NewSessionWithClient")
}
return Session{
apiKey: apiKey,
client: client,
}
}
// NewSession creates a new Session with the given API key.
// It uses the default client to make requests to the SolarSystems API.
func NewSession(apiKey string) Session {
return NewSessionWithClient(apiKey, http.DefaultClient)
}