-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstathat.go
59 lines (48 loc) · 1.99 KB
/
stathat.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
49
50
51
52
53
54
55
56
57
58
59
package stathat
import "errors"
// StatHat is a StatHat which does StatHat things
type StatHat struct {
token string
ezkey string
noop bool
}
// ErrMissingToken means the `StatHat` was missing an `token` value.
// That value is set usually set like this: `stathat.New().Token("sometoken").EZKey("somekey")` (both `Token` and `EZKey` are optional, but various methods need one or the other to have been set).
var ErrMissingToken = errors.New("missing token")
// ErrMissingEZKey means the `StatHat` was missing an `ezkey` value.
// That value is set usually set like this: `stathat.New().Token("sometoken").EZKey("somekey")` (both `Token` and `EZKey` are optional, but various methods need one or the other to have been set).
var ErrMissingEZKey = errors.New("missing ezkey")
// New returns a StatHat.
// You'll want to set either/both of the `Token` or `EZKey` values.
func New() StatHat {
return StatHat{}
}
// Noop causes any stats to be silently dropped instead of being recorded.
// This is useful at times when you want to opt out of recording stats but not want to unwire the stat calls.
// Writes won't happen (deleting and stat value sending), but any reads will still fetch.
// Writes will return nil for error, since they didn't fail but were simply ignored.
func (s StatHat) Noop() StatHat {
s.noop = true
return s
}
// Token sets the access token (see https://www.stathat.com/access).
// It returns an updated StatHat with the token added. It does not modify the original StatHat.
func (s StatHat) Token(token string) StatHat {
s.token = token
return s
}
// EZKey sets the ezkey value.
// It returns an updated StatHat with the token added. It does not modify the original StatHat.
func (s StatHat) EZKey(ezkey string) StatHat {
s.ezkey = ezkey
return s
}
func (s StatHat) apiPrefix() string {
return `https://www.stathat.com/x/` + s.token
}
func (s StatHat) ezPrefix() string {
return `https://api.stathat.com/ez`
}
func (s StatHat) classicPrefix() string {
return `https://api.stathat.com/c`
}