优化边缘节点在线状态管理

This commit is contained in:
GoEdgeLab
2021-11-20 18:59:35 +08:00
parent 7879c4c114
commit 51d144cb53
5 changed files with 63 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ import (
var sharedAPIConfig *APIConfig = nil
var PaddingId string
// API节点配置
// APIConfig API节点配置
type APIConfig struct {
NodeId string `yaml:"nodeId" json:"nodeId"`
Secret string `yaml:"secret" json:"secret"`
@@ -21,7 +21,7 @@ type APIConfig struct {
numberId int64 // 数字ID
}
// 获取共享配置
// SharedAPIConfig 获取共享配置
func SharedAPIConfig() (*APIConfig, error) {
sharedLocker.Lock()
defer sharedLocker.Unlock()
@@ -96,18 +96,19 @@ func SharedAPIConfig() (*APIConfig, error) {
return config, nil
}
// 设置数字ID
// SetNumberId 设置数字ID
func (this *APIConfig) SetNumberId(numberId int64) {
this.numberId = numberId
teaconst.NodeId = numberId
PaddingId = fmt.Sprintf("%08d", numberId)
}
// 获取数字ID
// NumberId 获取数字ID
func (this *APIConfig) NumberId() int64 {
return this.numberId
}
// 保存到文件
// WriteFile 保存到文件
func (this *APIConfig) WriteFile(path string) error {
data, err := yaml.Marshal(this)
if err != nil {