ircd/irc/config.go

54 lines
849 B
Go
Raw Normal View History

2014-02-09 15:53:42 +00:00
package irc
import (
"encoding/json"
"os"
)
type Config struct {
2014-02-12 00:35:32 +00:00
Debug map[string]bool
2014-02-10 03:41:00 +00:00
Listeners []ListenerConfig
2014-02-12 00:35:32 +00:00
MOTD string
Name string
2014-02-09 18:07:40 +00:00
Operators []OperatorConfig
2014-02-12 00:35:32 +00:00
Password string
2014-02-09 18:07:40 +00:00
}
type OperatorConfig struct {
2014-02-09 15:53:42 +00:00
Name string
Password string
}
2014-02-10 03:41:00 +00:00
type ListenerConfig struct {
2014-02-10 21:52:28 +00:00
Net string
2014-02-10 03:41:00 +00:00
Address string
Key string
Certificate string
}
func (config *ListenerConfig) IsTLS() bool {
return (config.Key != "") && (config.Certificate != "")
}
2014-02-09 15:53:42 +00: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 21:52:28 +00:00
if err != nil {
return
}
for _, lconf := range config.Listeners {
if lconf.Net == "" {
lconf.Net = "tcp"
}
}
2014-02-09 15:53:42 +00:00
return
}