-
Notifications
You must be signed in to change notification settings - Fork 31
/
urls.go
62 lines (55 loc) · 1.84 KB
/
urls.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
package config
import (
"encoding/json"
"io/ioutil"
)
// URLs represents a set of URLs where Anki's cloud services can be reached
type URLs struct {
JDocs string `json:"jdocs"`
Token string `json:"tms"`
Chipper string `json:"chipper"`
Check string `json:"check"`
LogFiles string `json:"logfiles"`
AppKey string `json:"appkey"`
OffboardVision *string `json:"offboard_vision,omitempty"`
}
// DefaultURLs provides a default, hard-coded configuration that can be used
// if an expected configuration is not found on disk
var DefaultURLs = URLs{
JDocs: "jdocs-dev.api.anki.com:443",
Token: "token-dev.api.anki.com:443",
Chipper: "chipper-dev.api.anki.com:443",
Check: "conncheck.global.anki-dev-services.com/ok",
LogFiles: "s3://anki-device-logs-dev/victor",
AppKey: "",
}
// Env represents the URLs associated with the most recent successful call to
// SetGlobal. Before this, it has the same values as DefaultURLs.
var Env = DefaultURLs
// SetGlobal sets the public Env variable to the URLs in the given filename. If the given
// filename is blank, a known hardcoded location for server_config.json on the robot is used.
func SetGlobal(filename string) error {
urls, err := LoadURLs(filename)
if err != nil {
return err
}
Env = *urls
return nil
}
var defaultFilename = "/anki/data/assets/cozmo_resources/config/server_config.json"
// LoadURLs attempts to load a URL config from the given filename. If the given filename
// is blank, a known hardcoded location for server_config.json on the robot is used.
func LoadURLs(filename string) (*URLs, error) {
if filename == "" {
filename = defaultFilename
}
buf, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
var urls URLs
if err := json.Unmarshal(buf, &urls); err != nil {
return nil, err
}
return &urls, nil
}