-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
57 lines (49 loc) · 1.11 KB
/
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
54
55
56
57
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
"gopkg.in/yaml.v3"
)
type yamlConfig struct {
Control string `yaml:"control"`
Token string `yaml:"token"`
}
var adminConfig map[string]interface{}
var vhostListConfig []map[string]interface{}
var nodeConfig yamlConfig
func init() {
// NodeConfig
yamlFile, err := ioutil.ReadFile("static/config.yaml")
if err != nil {
fmt.Printf("yamlFile.Get err #%v ", err)
}
yamlFileR := strings.ReplaceAll(string(yamlFile), "{ctrlServer}", "")
err = yaml.Unmarshal([]byte(yamlFileR), &nodeConfig)
if err != nil {
fmt.Println("Unmarshal", err)
}
upAdminConfig()
upVhostConfig()
}
func upAdminConfig() {
jsonFile, err := ioutil.ReadFile("config.json")
if err != nil {
fmt.Printf("jsonFile.Get err #%v ", err)
}
err = json.Unmarshal(jsonFile, &adminConfig)
if err != nil {
fmt.Println("Unmarshal", err)
}
}
func upVhostConfig() {
jsonFile, err := ioutil.ReadFile("vhost.json")
if err != nil {
fmt.Printf("jsonFile.Get err #%v ", err)
}
err = json.Unmarshal(jsonFile, &vhostListConfig)
if err != nil {
fmt.Println("Unmarshal", err)
}
}