1.新增服务和Global配置接口,支持通过结构体解析

2.优化日志
This commit is contained in:
boyce
2024-05-15 10:06:50 +08:00
parent 78cc33c84e
commit 90d54bf3e2
3 changed files with 41 additions and 1 deletions

View File

@@ -14,6 +14,7 @@ import (
"sync"
"sync/atomic"
"github.com/duanhf2012/origin/v2/concurrent"
"encoding/json"
)
var timerDispatcherLen = 100000
@@ -295,6 +296,24 @@ func (s *Service) GetServiceCfg()interface{}{
return s.serviceCfg
}
func (s *Service) ParseServiceCfg(cfg interface{}) error{
if s.serviceCfg == nil {
return errors.New("no service configuration found")
}
rv := reflect.ValueOf(s.serviceCfg)
if rv.Kind() == reflect.Ptr && rv.IsNil() {
return errors.New("no service configuration found")
}
bytes,err := json.Marshal(s.serviceCfg)
if err != nil {
return err
}
return json.Unmarshal(bytes,cfg)
}
func (s *Service) GetProfiler() *profiler.Profiler{
return s.profiler
}

View File

@@ -23,7 +23,7 @@ func Init() {
for _,s := range setupServiceList {
err := s.OnInit()
if err != nil {
log.SError("Failed to initialize "+s.GetName()+" service:"+err.Error())
log.Error("Failed to initialize "+s.GetName()+" service",log.ErrorAttr("err",err))
os.Exit(1)
}
}