-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure.go
62 lines (58 loc) · 1.59 KB
/
configure.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
package configure
import (
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
)
type Config struct {
User struct {
Nick string `yaml:"nick"`
User string `yaml:"user"`
Identify bool `yaml:"identify"`
Password string `yaml:"password"`
} `yaml:"user"`
Server struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
UseTls bool `yaml:"use_tls"`
ServerAuth bool `yaml:"server_auth"`
ServerPassword string `yaml:"server_pass"`
} `yaml:"server"`
Channel struct {
ChannelName string `yaml:"channel_name"`
Greeting string `yaml:"greeting"`
CmdPrefix string `yaml:"cmd_prefix"`
AutoJoinOnKick bool `yaml:"auto_join_on_kick"`
} `yaml:"channel"`
Connection struct {
VerboseCallbackHandler bool `yaml:"verbose_callback_handler"`
Debug bool `yaml:"debug"`
} `yaml:"connection"`
Admin struct {
Owner string `yaml:"owner"`
DenyMessage string `yaml:"deny_message"`
} `yaml:"admin"`
Http struct {
ResponseSizeLimit int64 `yaml:"response_size_limit"`
Timeout int64 `yaml:"timeout"`
UserAgent string `yaml:"user_agent"`
} `yaml:"http"`
Ignore struct {
UsersToIgnore []string `yaml:"users_to_ignore"`
} `yaml:"ignore"`
Modules map[string]map[string]string `yaml:"modules"`
}
const confPathFmt = "%s/.config/irkbot/irkbot.yml"
func LoadConfig(cfg *Config) error {
confPath := fmt.Sprintf(confPathFmt, os.Getenv("HOME"))
confStr, err := ioutil.ReadFile(confPath)
if err != nil {
return err
}
err = yaml.Unmarshal(confStr, cfg)
if err != nil {
return err
}
return nil
}