33 lines
632 B
Go
33 lines
632 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
BotToken string `json:"bot_token"`
|
|
ChatID string `json:"chat_id"`
|
|
GeoIP_City string `json:"geoip_city"`
|
|
GeoIP_ASN 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
|
|
}
|