blob: f20ce9e8cfb122abe9f30fc055522106a2a768e8 (
plain)
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
|
package config
import (
"encoding/json"
"io/ioutil"
"os"
)
type config struct {
Hostnames []string `json:"hosts"`
Port int `json:"port"`
AllowHidden bool `json:"allow-hidden"`
HideHidden bool `json:"hide-hidden"`
Auth bool `json:"auth"`
RootPath string `json:"root-path"`
Cache bool `json:"cache"`
}
var Config config
func ReadConfig(path string) error {
if path == "" {
path = "config.json"
}
file, err := os.Open(path)
if err != nil {
return err
} else {
defer file.Close()
}
content, _ := ioutil.ReadAll(file)
json.Unmarshal(content, &Config)
return nil
}
func SetDefaultValue() {
Config.Hostnames = []string{"localhost"}
Config.Port = 0
Config.AllowHidden = false
Config.HideHidden = true
Config.Auth = false
Config.RootPath = "."
}
|