-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathobjects.go
41 lines (33 loc) · 884 Bytes
/
objects.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
package cli
import (
"encoding/json"
"github.com/pkg/errors"
"os"
)
func ConstructObjectsFromConfig() (map[string]interface{}, error) {
objects := make(map[string]interface{})
file, err := os.ReadFile("config.json")
if err != nil {
return nil, errors.Wrap(err, "could not open config.json file")
}
var config Config
if err := json.Unmarshal(file, &config); err != nil {
return nil, errors.Wrap(err, "failed unmarshaling json")
}
for _, object := range config.Objects {
switch object.Type {
case ObjectMessage:
objects[object.Name], err = NewMessage(object)
case ObjectDisplay:
objects[object.Name], err = NewDisplay(object)
case ObjectMemory:
objects[object.Name], err = NewMemory(object)
default:
return nil, errors.New("unknown object type: " + string(object.Type))
}
if err != nil {
return nil, err
}
}
return objects, nil
}