每个服务只初始化一次

This commit is contained in:
刘祥超
2022-09-22 11:09:11 +08:00
parent d9fb6a2c84
commit dd460bc40d
2 changed files with 16 additions and 0 deletions

View File

@@ -172,6 +172,11 @@ func (this *NodeConfig) Init() (err error, serverErrors []*ServerError) {
// servers // servers
for _, server := range this.Servers { for _, server := range this.Servers {
// 避免在运行时重新初始化
if server.IsInitialized() {
continue
}
// 初始化 // 初始化
errs := server.Init() errs := server.Init()
if len(errs) > 0 { if len(errs) > 0 {

View File

@@ -62,6 +62,8 @@ type ServerConfig struct {
// UAM // UAM
UAM *UAMConfig `yaml:"uam" json:"uam"` UAM *UAMConfig `yaml:"uam" json:"uam"`
isInitialized bool
isOk bool isOk bool
planId int64 planId int64
@@ -79,6 +81,11 @@ func NewServerConfig() *ServerConfig {
} }
func (this *ServerConfig) Init() (results []error) { func (this *ServerConfig) Init() (results []error) {
if this.isInitialized {
return
}
this.isInitialized = true
// 分解Group // 分解Group
if this.Group != nil && this.Group.IsOn { if this.Group != nil && this.Group.IsOn {
// reverse proxy // reverse proxy
@@ -266,6 +273,10 @@ func (this *ServerConfig) Init() (results []error) {
return nil return nil
} }
func (this *ServerConfig) IsInitialized() bool {
return this.isInitialized
}
// IsOk 配置是否正确 // IsOk 配置是否正确
func (this *ServerConfig) IsOk() bool { func (this *ServerConfig) IsOk() bool {
return this.isOk return this.isOk