-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
70 lines (59 loc) · 1.49 KB
/
util.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
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"context"
"errors"
"net/http"
"github.com/spf13/viper"
)
type ConfigParams struct {
Email string
SessionToken string
Address string
}
//
//func SerializeDeviceResponse(res httpclient.DeviceResponse) httpclient.DeviceResponse {
// p, _ := json.Marshal(res)
// var deviceResponse httpclient.DeviceResponse
// json.Unmarshal(p, &deviceResponse)
// return deviceResponse
//}
//
//func SerializeTrackingResponse(res httpclient.TrackingResponse) httpclient.TrackingResponse {
// p, _ := json.Marshal(res)
// var trackingResponse httpclient.TrackingResponse
// json.Unmarshal(p, &trackingResponse)
// return trackingResponse
//}
func checkAddressSet() bool {
if Address == "" {
return false
}
return true
}
func readValuesFromConfig() ConfigParams {
readConfig()
email := viper.GetString("email")
address := viper.GetString("address")
sessionToken := viper.GetString("session_token")
return ConfigParams{
Email: email,
Address: address,
SessionToken: sessionToken,
}
}
func setRequestHeaders() RequestEditorFn {
return func(ctx context.Context, req *http.Request) error {
req.Header.Set("Content-Type", "application/json")
return nil
}
}
func setBoxeeAuthHeaders(token string) RequestEditorFn {
return func(ctx context.Context, req *http.Request) error {
if token == "" {
return errors.New("empty token in X-Boxee-Auth header")
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Boxee-Auth", token)
return nil
}
}