Cache config, lock behind mutex

This commit is contained in:
ppeb
2025-04-27 15:29:09 -05:00
parent 9aba0bbeae
commit ad221202f2

View File

@@ -3,6 +3,8 @@ package common
import (
"encoding/xml"
"os"
"github.com/sasha-s/go-deadlock"
)
type Config struct {
@@ -48,10 +50,16 @@ type Config struct {
ServerName string `xml:"serverName,omitempty"`
}
var config Config
var configLoaded bool
var (
config Config
configLoaded bool
cmutex = deadlock.Mutex{}
)
func GetConfig() Config {
cmutex.Lock()
defer cmutex.Unlock()
if configLoaded {
return config
}
@@ -128,5 +136,7 @@ func GetConfig() Config {
config.AllowMultipleDeviceIDs = "never"
}
configLoaded = true
return config
}