]> code.octet-stream.net Git - broadcaster/blob - server/config.go
Make headings consistent in UI
[broadcaster] / server / config.go
1 package main
2
3 import (
4 "errors"
5 "log"
6
7 "github.com/BurntSushi/toml"
8 )
9
10 type ServerConfig struct {
11 BindAddress string
12 Port int
13 SqliteDB string
14 AudioFilesPath string
15 }
16
17 func NewServerConfig() ServerConfig {
18 return ServerConfig{
19 BindAddress: "0.0.0.0",
20 Port: 55134,
21 SqliteDB: "",
22 AudioFilesPath: "",
23 }
24 }
25
26 func (c *ServerConfig) LoadFromFile(path string) {
27 _, err := toml.DecodeFile(path, &c)
28 if err != nil {
29 log.Fatal("could not read config file for reading at path:", path, err)
30 }
31 err = c.Validate()
32 if err != nil {
33 log.Fatal(err)
34 }
35 }
36
37 func (c *ServerConfig) Validate() error {
38 if c.SqliteDB == "" {
39 return errors.New("Configuration must provide SqliteDB")
40 }
41 if c.AudioFilesPath == "" {
42 return errors.New("Configuration must provide AudioFilesPath")
43 }
44 return nil
45 }