ergo/irc/config.go

53 lines
831 B
Go
Raw Normal View History

2014-02-09 16:53:42 +01:00
package irc
import (
"encoding/json"
"os"
)
type Config struct {
2014-02-09 19:07:40 +01:00
Name string
2014-02-10 04:41:00 +01:00
Listeners []ListenerConfig
2014-02-09 19:07:40 +01:00
Password string
Operators []OperatorConfig
Debug map[string]bool
}
type OperatorConfig struct {
2014-02-09 16:53:42 +01:00
Name string
Password string
}
2014-02-10 04:41:00 +01:00
type ListenerConfig struct {
2014-02-10 22:52:28 +01:00
Net string
2014-02-10 04:41:00 +01:00
Address string
Key string
Certificate string
}
func (config *ListenerConfig) IsTLS() bool {
return (config.Key != "") && (config.Certificate != "")
}
2014-02-09 16:53:42 +01:00
func LoadConfig() (config *Config, err error) {
config = &Config{}
file, err := os.Open("ergonomadic.json")
if err != nil {
return
}
defer file.Close()
decoder := json.NewDecoder(file)
err = decoder.Decode(config)
2014-02-10 22:52:28 +01:00
if err != nil {
return
}
for _, lconf := range config.Listeners {
if lconf.Net == "" {
lconf.Net = "tcp"
}
}
2014-02-09 16:53:42 +01:00
return
}