update locks

This commit is contained in:
shoopea
2025-10-19 14:12:31 +02:00
parent ace13b68a8
commit 73f9551c8f
6 changed files with 75 additions and 37 deletions

View File

@@ -59,6 +59,17 @@ type EmailConfig struct {
ToEmail []string `json:"email_to,omitempty"`
}
func CfgLock() {
log.WithFields(log.Fields{}).Debugf("starting")
cfgMx.Lock()
}
func CfgUnlock() {
log.WithFields(log.Fields{}).Debugf("starting")
cfgMx.Unlock()
}
// Load config from file
func LoadConfigFile(path string) (*Config, error) {
log.WithFields(log.Fields{"path": path}).Debugf("starting")
@@ -194,8 +205,8 @@ func (c *Config) Pretty() ([]byte, error) {
log.WithFields(log.Fields{}).Debugf("starting")
defer log.WithFields(log.Fields{}).Debugf("done")
cfgMx.Lock()
defer cfgMx.Unlock()
CfgLock()
defer CfgUnlock()
b, err := json.Marshal(cfg)
if err != nil {
@@ -211,8 +222,8 @@ func (a *AppConfig) Pretty() ([]byte, error) {
log.WithFields(log.Fields{}).Debugf("starting")
defer log.WithFields(log.Fields{}).Debugf("done")
cfgMx.Lock()
defer cfgMx.Unlock()
CfgLock()
defer CfgUnlock()
b, err := json.Marshal(a)
if err != nil {
@@ -258,8 +269,8 @@ func (c *Config) Run() {
return
}
cfgMx.Lock()
defer cfgMx.Unlock()
CfgLock()
defer CfgUnlock()
cfgRun = true
defer func() { cfgRun = false }()