-
Notifications
You must be signed in to change notification settings - Fork 4
/
groupconfig.go
71 lines (61 loc) · 1.74 KB
/
groupconfig.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
71
package gghelper
import (
"encoding/json"
"io/ioutil"
)
type definition struct {
ID string `json:"id"`
VersionArn string `json:"version_arn"`
}
type function struct {
Arn string `json:"arn"`
ArnQualifier string `json:"arn_qualifier"`
}
type group struct {
Arn string `json:"arn"`
ID string `json:"id"`
Version string `json:"version"`
}
type thing struct {
CertArn string `json:"cert_arn"`
CertID string `json:"cert_id"`
ThingArn string `json:"thing_arn"`
ThingName string `json:"thing_name"`
}
type ggGroupConfig struct {
Core thing `json:"core"`
CoreDefinition definition `json:"core_def"`
DeviceDefinition definition `json:"device_def"`
Devices map[string]thing `json:"device,omitempty"`
FunctionDefinition definition `json:"func_def"`
Group group `json:"group"`
LambdaFunctions map[string]function `json:"lambda_functions,omitempty"`
LoggerDefinition definition `json:"logger_def"`
SubscriptionDefinition definition `json:"subscription_def"`
}
func (group *ggGroupConfig) LoadConfig(filename string) error {
data, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
json.Unmarshal(data, group)
if group.LambdaFunctions == nil {
group.LambdaFunctions = make(map[string]function)
}
return nil
}
func (group *ggGroupConfig) WriteConfig(filename string) error {
data, err := json.MarshalIndent(group, "", " ")
if err != nil {
return err
}
err = ioutil.WriteFile(filename, data, 0644)
if err != nil {
return err
}
return nil
}
func (group *ggGroupConfig) ClearConfig() {
newConfig := new(ggGroupConfig)
group = newConfig
}