Skip to content

Commit

Permalink
feat:support watch config_group (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Nov 4, 2023
1 parent f371bb2 commit da06acf
Show file tree
Hide file tree
Showing 37 changed files with 1,779 additions and 35 deletions.
7 changes: 7 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ type ConfigAPI interface {
PublishConfigFile(namespace, fileGroup, fileName string) error
}

// ConfigGroupAPI .
type ConfigGroupAPI interface {
api.SDKOwner
// GetConfigGroup .
GetConfigGroup(namesapce, group string) (model.ConfigFileGroup, error)
}

// RouterAPI routing api methods
type RouterAPI interface {
api.SDKOwner
Expand Down
15 changes: 15 additions & 0 deletions api/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ type ConfigFileAPI interface {
PublishConfigFile(namespace, fileGroup, fileName string) error
}

type ConfigGroupAPI interface {
SDKOwner
// GetConfigGroup 获取配置分组
GetConfigGroup(namespace, group string) (model.ConfigFileGroup, error)
}

var (
// NewConfigFileAPIBySDKContext 通过 SDKContext 创建 ConfigFileAPI
NewConfigFileAPIBySDKContext = newConfigFileAPIBySDKContext
Expand All @@ -41,4 +47,13 @@ var (
NewConfigFileAPIByConfig = newConfigFileAPIByConfig
// NewConfigFileAPIByFile 通过配置文件创建 ConfigFileAPI
NewConfigFileAPIByFile = newConfigFileAPIByFile

// NewConfigGroupAPIBySDKContext 通过 SDKContext 创建 ConfigGroupAPI
NewConfigGroupAPIBySDKContext = newConfigGroupAPIBySDKContext
// NewConfigGroupAPI 通过 polaris.yaml 创建 ConfigGroupAPI
NewConfigGroupAPI = newConfigGroupAPI
// NewConfigGroupAPIByConfig 通过 Configuration 创建 ConfigGroupAPI
NewConfigGroupAPIByConfig = newConfigGroupAPIByConfig
// NewConfigGroupAPIByFile 通过配置文件创建 ConfigGroupAPI
NewConfigGroupAPIByFile = newConfigGroupAPIByFile
)
40 changes: 40 additions & 0 deletions api/config_file_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,43 @@ func (c *configFileAPI) PublishConfigFile(namespace, fileGroup, fileName string)
func (c *configFileAPI) SDKContext() SDKContext {
return c.context
}

type configGroupAPI struct {
context SDKContext
}

func newConfigGroupAPI() (ConfigGroupAPI, error) {
return newConfigGroupAPIByConfig(config.NewDefaultConfigurationWithDomain())
}

func newConfigGroupAPIByConfig(cfg config.Configuration) (ConfigGroupAPI, error) {
context, err := InitContextByConfig(cfg)
if err != nil {
return nil, err
}
return &configGroupAPI{context}, nil
}

func newConfigGroupAPIByFile(path string) (ConfigGroupAPI, error) {
context, err := InitContextByFile(path)
if err != nil {
return nil, err
}
return &configGroupAPI{context}, nil
}

func newConfigGroupAPIBySDKContext(context SDKContext) ConfigGroupAPI {
return &configGroupAPI{
context: context,
}
}

// GetConfigGroup 获取配置分组
func (c *configGroupAPI) GetConfigGroup(namespace, group string) (model.ConfigFileGroup, error) {
return c.context.GetEngine().SyncGetConfigGroup(namespace, group)
}

// SDKContext 获取SDK上下文
func (c *configGroupAPI) SDKContext() SDKContext {
return c.context
}
55 changes: 55 additions & 0 deletions api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package polaris
import (
"github.com/polarismesh/polaris-go/api"
"github.com/polarismesh/polaris-go/pkg/config"
"github.com/polarismesh/polaris-go/pkg/model"
)

type configAPI struct {
Expand Down Expand Up @@ -91,3 +92,57 @@ func (c *configAPI) PublishConfigFile(namespace, fileGroup, fileName string) err
func (c *configAPI) SDKContext() api.SDKContext {
return c.rawAPI.SDKContext()
}

type configGroupAPI struct {
rawAPI api.ConfigGroupAPI
}

// NewConfigGroupAPI 获取配置中心 API
func NewConfigGroupAPI() (ConfigGroupAPI, error) {
rawAPI, err := api.NewConfigGroupAPI()
if err != nil {
return nil, err
}
return &configGroupAPI{
rawAPI: rawAPI,
}, nil
}

// NewConfigAPIByConfig 通过配置对象获取配置中心 API

Check warning on line 111 in api_config.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.19.x)

comment on exported function NewConfigGroupAPIByConfig should be of the form "NewConfigGroupAPIByConfig ..."
func NewConfigGroupAPIByConfig(cfg config.Configuration) (ConfigGroupAPI, error) {
rawAPI, err := api.NewConfigGroupAPIByConfig(cfg)
if err != nil {
return nil, err
}
return &configGroupAPI{
rawAPI: rawAPI,
}, nil
}

// NewConfigAPIByFile 通过配置文件获取配置中心 API
func NewConfigGroupAPIByFile(path string) (ConfigGroupAPI, error) {
rawAPI, err := api.NewConfigGroupAPIByFile(path)
if err != nil {
return nil, err
}
return &configGroupAPI{
rawAPI: rawAPI,
}, nil
}

// NewConfigAPIByContext 通过上下文对象获取配置中心 API
func NewConfigGroupAPIByContext(context api.SDKContext) ConfigGroupAPI {
rawAPI := api.NewConfigGroupAPIBySDKContext(context)
return &configGroupAPI{
rawAPI: rawAPI,
}
}

func (c *configGroupAPI) GetConfigGroup(namesapce, group string) (model.ConfigFileGroup, error) {
return c.rawAPI.GetConfigGroup(namesapce, group)
}

// SDKContext 获取SDK上下文
func (c *configGroupAPI) SDKContext() api.SDKContext {
return c.rawAPI.SDKContext()
}
2 changes: 1 addition & 1 deletion examples/activehealthcheck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/polarismesh/polaris-go-active-healthcheck

go 1.17

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

require (
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion examples/circuitbreaker/consumer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/polarismesh/polaris-go-circuitbreaker-consumer

go 1.17

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

require (
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion examples/circuitbreaker/provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/polarismesh/polaris-go-circuitbreaker-provider

go 1.17

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

require (
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion examples/configuration/crud/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.4.0 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/configuration/crud/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.4.0 h1:fm7sUtFZC2g9+lLmRCtjGrUow47CY5JDFoZXwwCQGGY=
github.com/polarismesh/specification v1.4.0/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1 h1:lTZqeyUhhWuKyr6NDKBwmUrNfcUDvKLxWT/uOq71T5A=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down
2 changes: 1 addition & 1 deletion examples/configuration/encrypt/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/polarismesh/polaris-go-configuration

go 1.17

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

require (
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion examples/configuration/fallback/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/polarismesh/polaris-go-configuration

go 1.17

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

require (
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
38 changes: 38 additions & 0 deletions examples/configuration/group/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module github.com/polarismesh/polaris-go-configuration

go 1.17

require github.com/polarismesh/polaris-go v1.5.5

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/polarismesh/polaris-go => ../../../
Loading

0 comments on commit da06acf

Please sign in to comment.