Moved config module to utils package
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user