-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
52 lines (45 loc) · 1.53 KB
/
config.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
// a struct implementation of common.UserConfig interface
package common
import (
"time"
"github.com/getlantern/timezone"
)
// an implementation of common.UserConfig
type UserConfigData struct {
AppName string
DeviceID string
UserID int64
Token string
Language string
Headers map[string]string
}
func (uc *UserConfigData) GetAppName() string { return uc.AppName }
func (uc *UserConfigData) GetDeviceID() string { return uc.DeviceID }
func (uc *UserConfigData) GetUserID() int64 { return uc.UserID }
func (uc *UserConfigData) GetToken() string { return uc.Token }
func (uc *UserConfigData) GetLanguage() string { return uc.Language }
func (uc *UserConfigData) GetTimeZone() (string, error) { return timezone.IANANameForTime(time.Now()) }
func (uc *UserConfigData) GetEnabledExperiments() []string { return nil }
func (uc *UserConfigData) GetInternalHeaders() map[string]string {
h := make(map[string]string)
for k, v := range uc.Headers {
h[k] = v
}
return h
}
var _ UserConfig = (*UserConfigData)(nil)
// NewUserConfigData constucts a new UserConfigData (common.UserConfig) with the given options.
func NewUserConfigData(appName string, deviceID string, userID int64, token string, headers map[string]string, lang string) *UserConfigData {
uc := &UserConfigData{
AppName: appName,
DeviceID: deviceID,
UserID: userID,
Token: token,
Language: lang,
Headers: make(map[string]string),
}
for k, v := range headers {
uc.Headers[k] = v
}
return uc
}