nmdc-telegramfrontend/NTFConfig.go

46 lines
953 B
Go
Raw Normal View History

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