-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
43 lines (37 loc) · 1.05 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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
type Config struct {
Dirs []string `json:"dirs, omitempty"`
Files []string `json:"files, omitempty"`
Remote bool `json:"remote"`
Label string `json:"label"`
RemoteConfig RemoteConfig `json:"remote_config, omitempty"`
Ignore IgnoreList `json:"ignore"`
}
type RemoteConfig struct {
Repo string `json:"repo"`
ApiToken string `json:"api_token"`
}
func LoadConfig() (Config, error) {
var c Config
// raise error if erkconfig.json is nor found in current directory.
if !CheckFileExistence(CONF_FILENAME) {
return c, fmt.Errorf("Configuration file: %s is not found. please run \"erk init\" first.", CONF_FILENAME)
}
// read json config file.
// [todo] - lint json file syntax(is there some json linting impl for golang?)
body, err := ioutil.ReadFile(CONF_FILENAME)
if err != nil {
return c, err
}
// parse json and put them into Config struct.
err = json.Unmarshal(body, &c)
if err != nil {
return c, err
}
return c, nil
}