3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-02 00:49:25 +01:00
ergo/irc/config.go

54 lines
849 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-12 01:35:32 +01:00
Debug map[string]bool
2014-02-10 04:41:00 +01:00
Listeners []ListenerConfig
2014-02-12 01:35:32 +01:00
MOTD string
Name string
2014-02-09 19:07:40 +01:00
Operators []OperatorConfig
2014-02-12 01:35:32 +01:00
Password string
2014-02-09 19:07:40 +01:00
}
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
}