-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathconfig.go
41 lines (37 loc) · 916 Bytes
/
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
package main
import (
"encoding/json"
"io/ioutil"
"os"
)
// Config for initialized robot and server
type Config struct {
Server string `json:"server"`
Port int `json:"port"`
Cert string `json:"cert"`
CertKey string `json:"cert_key"`
WebHookURL string `json:"webhook_url"`
RedisAddress string `json:"redis_address"`
RedisPort int `json:"redis_port"`
RedisDB int `json:"redis_db"`
RedisPassword string `json:"redis_password"`
RobotName string `json:"robot_name"`
RobotToken string `json:"robot_token"`
}
// ParseConfig parses config from the given file path
func ParseConfig(path string) (config *Config, err error) {
file, err := os.Open(path)
if err != nil {
return
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
return
}
config = &Config{}
if err = json.Unmarshal(data, config); err != nil {
return nil, err
}
return
}