path to refreshing states from email that doesnt work over vpn

This commit is contained in:
Bel LaPointe
2022-01-09 23:42:53 -05:00
parent 485293466e
commit 366b35d76b
3 changed files with 40 additions and 6 deletions

View File

@@ -28,12 +28,16 @@ type Config struct {
var live Config
func Refresh() error {
configPath, ok := os.LookupEnv("CONFIG")
func configPath() string {
p, ok := os.LookupEnv("CONFIG")
if !ok {
configPath = "./config.json"
p = "./config.json"
}
b, err := ioutil.ReadFile(configPath)
return p
}
func Refresh() error {
b, err := ioutil.ReadFile(configPath())
if err != nil {
return err
}
@@ -52,6 +56,15 @@ func Get() *Config {
return &live
}
func Set(other Config) {
b, err := json.Marshal(other)
if err != nil {
return
}
ioutil.WriteFile(configPath(), b, os.ModePerm)
Refresh()
}
func (c *Config) DB() storage.DB {
if c.db == nil {
c.lock.Lock()