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 = "." }