-
Notifications
You must be signed in to change notification settings - Fork 2
/
graph_config.go
53 lines (49 loc) · 1.4 KB
/
graph_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
53
package graph_engine_go
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
// 节点配置
type GraphNodeConfig struct {
Name string `json:"name"`
NodeType string `json:"type"`
Emitters map[string]string `json:"emitters"`
Depends map[string]string `json:"depends"`
Config map[string]string `json:"config"`
}
// 整图结构的配置
type GraphConfig struct {
Name string `json:"name"`
TypeName string `json:"type"`
Include []string `json:"include"`
PoolSize int `json:"pool_size"`
NumThreads int `json:"num_threads"`
Nodes []GraphNodeConfig `json:"nodes"`
}
// 载入关于图结构信息描述的json文件
func LoadGraphConfig(configJson string) (*GraphConfig, error) {
// 检查路径是否存在
_, err := os.Stat(configJson)
if os.IsNotExist(err) {
return nil, nil
}
// 打开并读取json文件
jsonFile, err := os.Open(configJson)
if err != nil {
return nil, fmt.Errorf("failed to parse json file:%s", configJson)
}
defer jsonFile.Close()
byteValues, err := ioutil.ReadAll(jsonFile)
if err != nil {
return nil, fmt.Errorf("failed to read data from json file:%s", configJson)
}
// 解析json数据
var graphConfig GraphConfig
err = json.Unmarshal(byteValues, &graphConfig)
if err != nil {
return nil, fmt.Errorf("failed to parse json:%s", configJson)
}
return &graphConfig, nil
}