-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
69 lines (61 loc) · 1.31 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"log"
"os/user"
"gopkg.in/ini.v1"
)
type Config struct {
Mumble mumbleConfig `ini:"mumble"`
Cache cacheConfig `ini:"cache"`
Queue queueConfig `ini:"queue"`
}
type mumbleConfig struct {
Username string `ini:"username"`
Password string `ini:"password"`
Address string `ini:"address"`
Port string `ini:"port"`
}
type cacheConfig struct {
Directory string `ini:"directory"`
MaxSize int `ini:"maxsize"`
MaxFilesize string `ini:"maxfilesize"`
}
type queueConfig struct {
MaxSize int `ini:"maxsize"`
}
// NewConfig returns a new config with default settings.
func NewConfig() *Config {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
return &Config{
Mumble: mumbleConfig{
Username: "Jukebox",
Port: "64738",
},
Cache: cacheConfig{
Directory: fmt.Sprintf("%s/.cache/mumble-jukebox", usr.HomeDir),
MaxFilesize: "100m",
MaxSize: 10,
},
Queue: queueConfig{
MaxSize: 50,
},
}
}
// ReadConfig returns a new config with the default settings, overridden by the
// settings in the config file..
func ReadConfig(filename string) (*Config, error) {
cfg, err := ini.Load(filename)
if err != nil {
return nil, err
}
config := NewConfig()
err = cfg.MapTo(config)
if err != nil {
return nil, err
}
return config, nil
}