nmdc-telegramfrontend/NTFConfig.go
2018-06-03 15:27:50 +12:00

40 lines
658 B
Go

package main
import (
"encoding/json"
"io/ioutil"
)
type NTFConfig struct {
HubAddr string
BotAPIKey string
GroupChatID int64
// Map of telegram user IDs to NMDC nicks
KnownUsers map[int64]string
}
func LoadConfig(configFile string) (NTFConfig, error) {
b, err := ioutil.ReadFile(configFile)
if err != nil {
return NTFConfig{}, err
}
ret := NTFConfig{}
err = json.Unmarshal(b, &ret)
if err != nil {
return NTFConfig{}, err
}
return ret, nil
}
func (this *NTFConfig) Save(configFile string) error {
b, err := json.MarshalIndent(this, "", " ")
if err != nil {
return err
}
return ioutil.WriteFile(configFile, b, 0644)
}