-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
51 lines (44 loc) · 892 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
42
43
44
45
46
47
48
49
50
51
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"path/filepath"
)
type MyConfig struct {
Server string
Port string
Username string
Password string
Base_dir string
Include_dir []string
Exclude_dir []string
}
var config MyConfig
func loadConfig(config_file_path string) {
json_dat, err := ioutil.ReadFile(config_file_path)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal([]byte(json_dat), &config)
if err != nil {
log.Fatal("Please provide valid json :- ", err)
}
if len(config.Include_dir) == 0 {
config.Include_dir = append(config.Include_dir, "/")
}
if config.Username == "" {
config.Username = "anonymous"
}
if config.Password == "" {
config.Password = "anonymous"
}
if config.Base_dir == "" {
ex, eerr := os.Executable()
if eerr != nil {
log.Fatal(eerr)
}
config.Base_dir = filepath.Dir(ex)
}
}