X-Git-Url: https://code.octet-stream.net/broadcaster/blobdiff_plain/7423c6c97eb5d6dc063e7185c50137bbb5e25a23..7b615b3c71825b5b229b78509a16db37e1d3f38d:/server/config.go diff --git a/server/config.go b/server/config.go new file mode 100644 index 0000000..4a4866c --- /dev/null +++ b/server/config.go @@ -0,0 +1,45 @@ +package main + +import ( + "errors" + "log" + + "github.com/BurntSushi/toml" +) + +type ServerConfig struct { + BindAddress string + Port int + SqliteDB string + AudioFilesPath string +} + +func NewServerConfig() ServerConfig { + return ServerConfig{ + BindAddress: "0.0.0.0", + Port: 55134, + SqliteDB: "", + AudioFilesPath: "", + } +} + +func (c *ServerConfig) LoadFromFile(path string) { + _, err := toml.DecodeFile(path, &c) + if err != nil { + log.Fatal("could not read config file for reading at path:", path, err) + } + err = c.Validate() + if err != nil { + log.Fatal(err) + } +} + +func (c *ServerConfig) Validate() error { + if c.SqliteDB == "" { + return errors.New("Configuration must provide SqliteDB") + } + if c.AudioFilesPath == "" { + return errors.New("Configuration must provide AudioFilesPath") + } + return nil +}