mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-29 15:40:02 +01:00
54 lines
849 B
Go
54 lines
849 B
Go
package irc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
Debug map[string]bool
|
|
Listeners []ListenerConfig
|
|
MOTD string
|
|
Name string
|
|
Operators []OperatorConfig
|
|
Password string
|
|
}
|
|
|
|
type OperatorConfig struct {
|
|
Name string
|
|
Password string
|
|
}
|
|
|
|
type ListenerConfig struct {
|
|
Net string
|
|
Address string
|
|
Key string
|
|
Certificate string
|
|
}
|
|
|
|
func (config *ListenerConfig) IsTLS() bool {
|
|
return (config.Key != "") && (config.Certificate != "")
|
|
}
|
|
|
|
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)
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, lconf := range config.Listeners {
|
|
if lconf.Net == "" {
|
|
lconf.Net = "tcp"
|
|
}
|
|
}
|
|
return
|
|
}
|