36 lines
865 B
Go
36 lines
865 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"fmt"
|
|
)
|
|
|
|
type Config struct {
|
|
IRCServer string `json:"irc_server"`
|
|
IRCPort int `json:"irc_port"`
|
|
SSL bool `json:"ssl"`
|
|
Nickname string `json:"nickname"`
|
|
Channels []string `json:"channels"`
|
|
GeoIPDatabase string `json:"geoip_database"`
|
|
GeoIPASN string `json:"geoip_asn"`
|
|
Debug bool `json:"debug"`
|
|
}
|
|
|
|
func LoadConfig(file string) (Config, error) {
|
|
var config Config
|
|
|
|
configFile, err := os.Open(file)
|
|
if err != nil {
|
|
return config, fmt.Errorf("error opening config file: %v", err)
|
|
}
|
|
defer configFile.Close()
|
|
|
|
err = json.NewDecoder(configFile).Decode(&config)
|
|
if err != nil {
|
|
return config, fmt.Errorf("error decoding config file: %v", err)
|
|
}
|
|
|
|
return config, nil
|
|
}
|