nmdc-telegramfrontend/NTFConfig.go
2018-06-03 16:39:45 +12:00

46 lines
953 B
Go

package main
import (
"encoding/json"
"io/ioutil"
)
// NTFConfig keeps track of setup properties as well as runtime state.
// FIXME separate compile-time and run-time properties into separate files
type NTFConfig struct {
HubAddr string
HubDescription string
BotAPIKey string
GroupChatID int64
// Map of telegram user IDs to NMDC nicks
KnownUsers map[int64]string
// Map of telegram users known to be in the group chat ==> telegram displayname
GroupChatMembers 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)
}