38 lines
882 B
Go
38 lines
882 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"`
|
|
FontSize string `json:"fontSize"` //format is "8x12"
|
|
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
|
|
}
|