add go modules
This commit is contained in:
34
util/config.go
Normal file
34
util/config.go
Normal file
@ -0,0 +1,34 @@
|
||||
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"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user