Skip to content

Commit da06acf

Browse files
authored
feat:support watch config_group (#187)
1 parent f371bb2 commit da06acf

File tree

37 files changed

+1779
-35
lines changed

37 files changed

+1779
-35
lines changed

api.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ type ConfigAPI interface {
147147
PublishConfigFile(namespace, fileGroup, fileName string) error
148148
}
149149

150+
// ConfigGroupAPI .
151+
type ConfigGroupAPI interface {
152+
api.SDKOwner
153+
// GetConfigGroup .
154+
GetConfigGroup(namesapce, group string) (model.ConfigFileGroup, error)
155+
}
156+
150157
// RouterAPI routing api methods
151158
type RouterAPI interface {
152159
api.SDKOwner

api/config_file.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ type ConfigFileAPI interface {
3232
PublishConfigFile(namespace, fileGroup, fileName string) error
3333
}
3434

35+
type ConfigGroupAPI interface {
36+
SDKOwner
37+
// GetConfigGroup 获取配置分组
38+
GetConfigGroup(namespace, group string) (model.ConfigFileGroup, error)
39+
}
40+
3541
var (
3642
// NewConfigFileAPIBySDKContext 通过 SDKContext 创建 ConfigFileAPI
3743
NewConfigFileAPIBySDKContext = newConfigFileAPIBySDKContext
@@ -41,4 +47,13 @@ var (
4147
NewConfigFileAPIByConfig = newConfigFileAPIByConfig
4248
// NewConfigFileAPIByFile 通过配置文件创建 ConfigFileAPI
4349
NewConfigFileAPIByFile = newConfigFileAPIByFile
50+
51+
// NewConfigGroupAPIBySDKContext 通过 SDKContext 创建 ConfigGroupAPI
52+
NewConfigGroupAPIBySDKContext = newConfigGroupAPIBySDKContext
53+
// NewConfigGroupAPI 通过 polaris.yaml 创建 ConfigGroupAPI
54+
NewConfigGroupAPI = newConfigGroupAPI
55+
// NewConfigGroupAPIByConfig 通过 Configuration 创建 ConfigGroupAPI
56+
NewConfigGroupAPIByConfig = newConfigGroupAPIByConfig
57+
// NewConfigGroupAPIByFile 通过配置文件创建 ConfigGroupAPI
58+
NewConfigGroupAPIByFile = newConfigGroupAPIByFile
4459
)

api/config_file_impl.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,43 @@ func (c *configFileAPI) PublishConfigFile(namespace, fileGroup, fileName string)
7676
func (c *configFileAPI) SDKContext() SDKContext {
7777
return c.context
7878
}
79+
80+
type configGroupAPI struct {
81+
context SDKContext
82+
}
83+
84+
func newConfigGroupAPI() (ConfigGroupAPI, error) {
85+
return newConfigGroupAPIByConfig(config.NewDefaultConfigurationWithDomain())
86+
}
87+
88+
func newConfigGroupAPIByConfig(cfg config.Configuration) (ConfigGroupAPI, error) {
89+
context, err := InitContextByConfig(cfg)
90+
if err != nil {
91+
return nil, err
92+
}
93+
return &configGroupAPI{context}, nil
94+
}
95+
96+
func newConfigGroupAPIByFile(path string) (ConfigGroupAPI, error) {
97+
context, err := InitContextByFile(path)
98+
if err != nil {
99+
return nil, err
100+
}
101+
return &configGroupAPI{context}, nil
102+
}
103+
104+
func newConfigGroupAPIBySDKContext(context SDKContext) ConfigGroupAPI {
105+
return &configGroupAPI{
106+
context: context,
107+
}
108+
}
109+
110+
// GetConfigGroup 获取配置分组
111+
func (c *configGroupAPI) GetConfigGroup(namespace, group string) (model.ConfigFileGroup, error) {
112+
return c.context.GetEngine().SyncGetConfigGroup(namespace, group)
113+
}
114+
115+
// SDKContext 获取SDK上下文
116+
func (c *configGroupAPI) SDKContext() SDKContext {
117+
return c.context
118+
}

api_config.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package polaris
2020
import (
2121
"github.com/polarismesh/polaris-go/api"
2222
"github.com/polarismesh/polaris-go/pkg/config"
23+
"github.com/polarismesh/polaris-go/pkg/model"
2324
)
2425

2526
type configAPI struct {
@@ -91,3 +92,57 @@ func (c *configAPI) PublishConfigFile(namespace, fileGroup, fileName string) err
9192
func (c *configAPI) SDKContext() api.SDKContext {
9293
return c.rawAPI.SDKContext()
9394
}
95+
96+
type configGroupAPI struct {
97+
rawAPI api.ConfigGroupAPI
98+
}
99+
100+
// NewConfigGroupAPI 获取配置中心 API
101+
func NewConfigGroupAPI() (ConfigGroupAPI, error) {
102+
rawAPI, err := api.NewConfigGroupAPI()
103+
if err != nil {
104+
return nil, err
105+
}
106+
return &configGroupAPI{
107+
rawAPI: rawAPI,
108+
}, nil
109+
}
110+
111+
// NewConfigAPIByConfig 通过配置对象获取配置中心 API
112+
func NewConfigGroupAPIByConfig(cfg config.Configuration) (ConfigGroupAPI, error) {
113+
rawAPI, err := api.NewConfigGroupAPIByConfig(cfg)
114+
if err != nil {
115+
return nil, err
116+
}
117+
return &configGroupAPI{
118+
rawAPI: rawAPI,
119+
}, nil
120+
}
121+
122+
// NewConfigAPIByFile 通过配置文件获取配置中心 API
123+
func NewConfigGroupAPIByFile(path string) (ConfigGroupAPI, error) {
124+
rawAPI, err := api.NewConfigGroupAPIByFile(path)
125+
if err != nil {
126+
return nil, err
127+
}
128+
return &configGroupAPI{
129+
rawAPI: rawAPI,
130+
}, nil
131+
}
132+
133+
// NewConfigAPIByContext 通过上下文对象获取配置中心 API
134+
func NewConfigGroupAPIByContext(context api.SDKContext) ConfigGroupAPI {
135+
rawAPI := api.NewConfigGroupAPIBySDKContext(context)
136+
return &configGroupAPI{
137+
rawAPI: rawAPI,
138+
}
139+
}
140+
141+
func (c *configGroupAPI) GetConfigGroup(namesapce, group string) (model.ConfigFileGroup, error) {
142+
return c.rawAPI.GetConfigGroup(namesapce, group)
143+
}
144+
145+
// SDKContext 获取SDK上下文
146+
func (c *configGroupAPI) SDKContext() api.SDKContext {
147+
return c.rawAPI.SDKContext()
148+
}

examples/activehealthcheck/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/polarismesh/polaris-go-active-healthcheck
22

33
go 1.17
44

5-
require github.com/polarismesh/polaris-go v1.4.3
5+
require github.com/polarismesh/polaris-go v1.5.5
66

77
require (
88
github.com/beorn7/perks v1.0.1 // indirect

examples/circuitbreaker/consumer/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/polarismesh/polaris-go-circuitbreaker-consumer
22

33
go 1.17
44

5-
require github.com/polarismesh/polaris-go v1.4.3
5+
require github.com/polarismesh/polaris-go v1.5.5
66

77
require (
88
github.com/beorn7/perks v1.0.1 // indirect

examples/circuitbreaker/provider/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/polarismesh/polaris-go-circuitbreaker-provider
22

33
go 1.17
44

5-
require github.com/polarismesh/polaris-go v1.4.3
5+
require github.com/polarismesh/polaris-go v1.5.5
66

77
require (
88
github.com/beorn7/perks v1.0.1 // indirect

examples/configuration/crud/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/modern-go/reflect2 v1.0.2 // indirect
1818
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
1919
github.com/pkg/errors v0.9.1 // indirect
20-
github.com/polarismesh/specification v1.4.0 // indirect
20+
github.com/polarismesh/specification v1.4.1 // indirect
2121
github.com/prometheus/client_golang v1.12.2 // indirect
2222
github.com/prometheus/client_model v0.2.0 // indirect
2323
github.com/prometheus/common v0.32.1 // indirect

examples/configuration/crud/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
372372
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
373373
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
374374
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
375-
github.com/polarismesh/specification v1.4.0 h1:fm7sUtFZC2g9+lLmRCtjGrUow47CY5JDFoZXwwCQGGY=
376-
github.com/polarismesh/specification v1.4.0/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
375+
github.com/polarismesh/specification v1.4.1 h1:lTZqeyUhhWuKyr6NDKBwmUrNfcUDvKLxWT/uOq71T5A=
376+
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
377377
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
378378
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
379379
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=

examples/configuration/encrypt/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/polarismesh/polaris-go-configuration
22

33
go 1.17
44

5-
require github.com/polarismesh/polaris-go v1.4.3
5+
require github.com/polarismesh/polaris-go v1.5.5
66

77
require (
88
github.com/beorn7/perks v1.0.1 // indirect

0 commit comments

Comments
 (0)