alchemyst/util/config.go
2019-10-26 23:32:32 +03:00

37 lines
817 B
Go

package util
import (
"encoding/json"
"flag"
"io/ioutil"
"log"
)
type Config struct {
Title string `json:"title"`
FpsLimit int `json:"fpsLimit, omitempty" validate:"required"`
Version string `json:"version"`
MainWindowSizeX int `json:"sizeX"`
MainWindowSizeY int `json:"sizeY"`
Font string `json:"font"`
Verbosity string `json:"verbosity"`
}
func LoadConfig() *Config {
var configArg string = "./config.json"
flag.StringVar(&configArg, "cfg", configArg, "config file location")
flag.Parse()
// get config
data, err := ioutil.ReadFile(configArg)
if err != nil {
log.Fatalf("Application couldn't read config at %s", configArg)
}
config := new(Config)
err = json.Unmarshal(data, config)
if err != nil {
log.Fatalln(err)
}
return config
}