/
eyegoconfig.go
55 lines (44 loc) · 913 Bytes
/
eyegoconfig.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
package eyego
import (
"fmt"
"encoding/json"
"io/ioutil"
)
type EyegoConfig struct {
TargetDir string `json:"target_dir"`
GoogleAPIKey string `json:"google_api_key"`
Cards []Card `json:"cards"`
}
type Card struct {
UploadKey string `json:"upload_key"`
MacAddress string `json:"mac_address"`
}
var config EyegoConfig
func ConfigFrom(path string) {
b, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
err = json.Unmarshal(b, &config)
if err != nil {
fmt.Print(err)
}
}
func SetConfig(_config EyegoConfig) {
config = _config
}
func Config() EyegoConfig {
return config
}
func DumpConfig(config EyegoConfig) {
data, _ := json.Marshal(config)
fmt.Printf("%s", data)
}
func GetCard(mac_address string) Card {
for i := range config.Cards {
if config.Cards[i].MacAddress == mac_address {
return config.Cards[i]
}
}
panic(fmt.Sprintf("no such card: %s", mac_address))
}