package config import ( "os" "strings" "sync" "go.wit.com/log" ) // an experiment to see if this is useful var saveMu sync.RWMutex // returns true if config is working okay func InitValid() bool { saveMu.Lock() defer saveMu.Unlock() if configPB == nil { // todo: try to re-init it here return false } return true } // saves your applications config file func Save() error { /* basedir, _ := filepath.Split(configPB.Filename) if err := os.MkdirAll(basedir, os.ModePerm); err != nil { return err } saveENV() saveMu.Lock() defer saveMu.Unlock() err := SavePB(configPB) */ return saveENV() } func saveENV() error { filename, err := getConfigFilenameENV() if err != nil { return err } saveMu.Lock() defer saveMu.Unlock() outENV, err := formatENV() if err == nil { log.Info("SAVEENV IS RUNNING") log.Info("SAVEENV IS RUNNING") log.Info("SAVEENV IS RUNNING") log.Info(outENV) } return os.WriteFile(filename, []byte(outENV), 0644) } func Get(flag string) string { saveMu.Lock() defer saveMu.Unlock() if configPB == nil { return "" } c := findByLower(flag) if c == nil { return "" } return c.Value } func True(flag string) bool { saveMu.Lock() defer saveMu.Unlock() if configPB == nil { return false } found := configPB.findByKey(flag) if found == nil { return false } if strings.ToLower(found.Value) == "true" { return true } return false } func Set(key string, newValue string) error { saveMu.Lock() defer saveMu.Unlock() if configPB == nil { return NotInitialized } found := configPB.findByKey(key) if found != nil { found.Value = newValue } newvar := new(Config) newvar.Key = key newvar.Value = newValue configPB.Append(newvar) return nil }