You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
923 B

package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"git.sporestack.com/SporeStack/settlers"
)
// SqliteFilename of :memory: uses an in-memory database.
type Configuration struct {
AdminToken string `json:"admin_token"`
SqliteFilename string `json:"sqlite_filename"`
Port string `json:"port"`
}
func validateConfiguration(jsonData []byte) (conf Configuration, err error) {
// We can't use json.Unmarshall and DisallowUnknownFields(), so we use NewDecoder
decoder := json.NewDecoder(bytes.NewReader(jsonData))
decoder.DisallowUnknownFields()
if err = decoder.Decode(&conf); err != nil {
return
}
if err = settlers.ValidateToken(conf.AdminToken); err != nil {
return
}
return
}
func configuration(configurationFile string) (conf Configuration, err error) {
jsonData, err := ioutil.ReadFile(configurationFile)
if err != nil {
return
}
return validateConfiguration(jsonData)
}