forked from icedream/go-footballdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_meta.go
38 lines (33 loc) · 972 Bytes
/
response_meta.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
package footballdata
import (
"net/http"
"strconv"
)
// Contains additional information returned by the Football-Data API in the HTTP headers.
// This includes the currently authenticated user and information about the rate limitation.
type ResponseMeta struct {
// Indicates the recognized user or returns "anonymous" if not authenticated.
AuthenticatedClient string
// Defines the seconds left to reset your request counter.
RequestCounterReset uint64
// Indicates the requests left.
RequestsAvailable uint64
}
func responseMetaFromHeaders(h http.Header) (r ResponseMeta) {
if v := h.Get("X-Authenticated-Client"); v != "" {
r.AuthenticatedClient = v
}
if v := h.Get("X-RequestCounter-Reset"); v != "" {
i, err := strconv.ParseUint(v, 10, 64)
if err != nil {
r.RequestCounterReset = i
}
}
if v := h.Get("X-Requests-Available"); v != "" {
i, err := strconv.ParseUint(v, 10, 64)
if err != nil {
r.RequestsAvailable = i
}
}
return
}