feat: sync httpdns sdk/platform updates without large binaries
This commit is contained in:
45
EdgeAPI/internal/setup/upgrade_config.go
Normal file
45
EdgeAPI/internal/setup/upgrade_config.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
)
|
||||
|
||||
var (
|
||||
sharedUpgradeConfig *systemconfigs.UpgradeConfig
|
||||
sharedUpgradeConfigTime time.Time
|
||||
sharedUpgradeConfigMu sync.Mutex
|
||||
)
|
||||
|
||||
const upgradeConfigTTL = 5 * time.Minute
|
||||
|
||||
// LoadUpgradeConfig 读取升级配置(带5分钟内存缓存)
|
||||
func LoadUpgradeConfig() (*systemconfigs.UpgradeConfig, error) {
|
||||
sharedUpgradeConfigMu.Lock()
|
||||
defer sharedUpgradeConfigMu.Unlock()
|
||||
|
||||
if sharedUpgradeConfig != nil && time.Since(sharedUpgradeConfigTime) < upgradeConfigTTL {
|
||||
return sharedUpgradeConfig, nil
|
||||
}
|
||||
|
||||
valueJSON, err := models.SharedSysSettingDAO.ReadSetting(nil, systemconfigs.SettingCodeUpgradeConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config := systemconfigs.NewUpgradeConfig()
|
||||
if len(valueJSON) > 0 {
|
||||
err = json.Unmarshal(valueJSON, config)
|
||||
if err != nil {
|
||||
return config, nil
|
||||
}
|
||||
}
|
||||
|
||||
sharedUpgradeConfig = config
|
||||
sharedUpgradeConfigTime = time.Now()
|
||||
return config, nil
|
||||
}
|
||||
Reference in New Issue
Block a user