From dc29c7e989f8761d902e8ffcbc19c131f893303a Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 21 Feb 2019 10:33:46 +0100 Subject: Config package --- config/config.go | 33 +++++++++++++++++++++++++++++++++ config/config.json | 4 ++++ 2 files changed, 37 insertions(+) create mode 100644 config/config.go create mode 100644 config/config.json (limited to 'config') diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..b46b0e1 --- /dev/null +++ b/config/config.go @@ -0,0 +1,33 @@ +package config + +import ( + "encoding/json" + "io/ioutil" + "os" +) + +type config struct { + Hostnames []string `json:"host"` + Port int `json:"port"` + AllowLocalPath bool `json:"allow-local-path"` + Auth bool `json:"auth"` + RootPath string `json:"root-path"` +} + +var Config config + +func ReadConfig() error { + file, err := os.Open("config.json") + + if err != nil { + return err + } else { + defer file.Close() + } + + content, _ := ioutil.ReadAll(file) + + json.Unmarshal(content, &Config) + + return nil +} diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000..2bd396d --- /dev/null +++ b/config/config.json @@ -0,0 +1,4 @@ +{ + "host":["localhost"], + "port": 8080 +} -- cgit v1.2.3