77 "github.com/alibaba/sentinel-golang/core/log/metric"
88 "github.com/alibaba/sentinel-golang/core/system"
99 "github.com/alibaba/sentinel-golang/util"
10+ "github.com/pkg/errors"
1011)
1112
1213// Initialization func initialize the Sentinel's runtime environment, including:
@@ -19,6 +20,19 @@ func InitDefault() error {
1920 return initSentinel ("" )
2021}
2122
23+ // InitWithParser initializes Sentinel using given config parser
24+ // parser deserializes the configBytes and return config.Entity
25+ func InitWithParser (configBytes []byte , parser func ([]byte ) (* config.Entity , error )) (err error ) {
26+ if parser == nil {
27+ return errors .New ("nil parser" )
28+ }
29+ confEntity , err := parser (configBytes )
30+ if err != nil {
31+ return err
32+ }
33+ return InitWithConfig (confEntity )
34+ }
35+
2236// InitWithConfig initializes Sentinel using given config.
2337func InitWithConfig (confEntity * config.Entity ) (err error ) {
2438 defer func () {
@@ -35,7 +49,7 @@ func InitWithConfig(confEntity *config.Entity) (err error) {
3549 if err != nil {
3650 return err
3751 }
38- config .SetDefaultConfig (confEntity )
52+ config .ResetGlobalConfig (confEntity )
3953 if err = config .OverrideConfigFromEnvAndInitLog (); err != nil {
4054 return err
4155 }
@@ -48,8 +62,7 @@ func InitWithConfigFile(configPath string) error {
4862 return initSentinel (configPath )
4963}
5064
51- // initCoreComponents init core components with default config
52- // it's better SetDefaultConfig before initCoreComponents
65+ // initCoreComponents init core components with global config
5366func initCoreComponents () error {
5467 if config .MetricLogFlushIntervalSec () > 0 {
5568 if err := metric .InitTask (); err != nil {
@@ -79,7 +92,7 @@ func initSentinel(configPath string) (err error) {
7992 }
8093 }()
8194 // Initialize general config and logging module.
82- if err = config .InitConfig (configPath ); err != nil {
95+ if err = config .InitConfigWithYaml (configPath ); err != nil {
8396 return err
8497 }
8598 return initCoreComponents ()
0 commit comments