diff --git a/config.json b/config.json new file mode 100644 index 0000000..ee3aedf --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "Addr": "0.0.0.0:5000" +} diff --git a/main.go b/main.go index 3acac9d..eaf686b 100644 --- a/main.go +++ b/main.go @@ -1,13 +1,35 @@ package main import ( + "encoding/json" + "fmt" "github.com/gorilla/mux" "net/http" + "os" ) +type Configuration struct { + Addr string +} + func main() { + file, fileErr := os.Open("config.json") + + if fileErr != nil { + fmt.Println("failed to open config:", fileErr) + os.Exit(1) + } + + configuration := new(Configuration) + configErr := json.NewDecoder(file).Decode(configuration) + + if configErr != nil { + fmt.Println("config error:", configErr) + os.Exit(1) + } + r := mux.NewRouter() GlobalHandler(r.PathPrefix("/global").Subrouter()) http.Handle("/", r) - http.ListenAndServe(":5000", nil) + http.ListenAndServe(configuration.Addr, nil) }