From 7ea5238695893c3cc403c0b16d7271b80d6bb832 Mon Sep 17 00:00:00 2001 From: smx_Moragn <1048492656@qq.com> Date: Thu, 12 Sep 2024 20:48:19 +0800 Subject: [PATCH] integration config --- config/apollo/apollo/apollo.go | 33 +-- config/apollo/apollo/apollo_test.go | 5 +- config/apollo/apollo/parser.go | 59 +---- config/apollo/client/circuit_breaker.go | 10 +- config/apollo/client/retry.go | 9 +- config/apollo/client/rpc_timetout.go | 5 +- config/apollo/client/suite.go | 6 +- config/apollo/go.mod | 1 + config/apollo/server/limiter.go | 5 +- config/consul/client/circult_breaker.go | 11 +- config/consul/client/degradation.go | 7 +- config/consul/client/retry.go | 11 +- config/consul/client/rpc_timeout.go | 7 +- config/consul/consul/consul.go | 31 +-- config/consul/consul/parser.go | 52 +--- config/consul/go.mod | 9 +- config/consul/server/limiter.go | 7 +- config/consul/utils/set.go | 46 ---- config/etcd/client/circuit_breaker.go | 11 +- config/etcd/client/degradation.go | 7 +- config/etcd/client/retry.go | 11 +- config/etcd/client/rpc_timeout.go | 7 +- config/etcd/etcd/etcd.go | 27 ++- config/etcd/etcd/parser.go | 28 --- config/etcd/go.mod | 2 - config/etcd/server/limiter.go | 7 +- config/etcd/utils/set.go | 46 ---- config/file/filewatcher/filewatcher.go | 205 ++++++++++++++++ config/file/go.mod | 5 +- config/file/mock/filewatcher_mock.go | 37 +++ config/file/monitor/monitor.go | 195 +++++++++++++++ config/file/monitor/monitor_test.go | 227 ++++++++++++++++++ config/file/utils/set.go | 46 ---- config/file/utils/set_test.go | 11 +- config/nacos/client/circuit_breaker.go | 5 +- config/nacos/client/retry.go | 5 +- config/nacos/go.mod | 3 +- config/nacos/utils/set.go | 46 ---- config/nacos/v2/client/circuit_breaker.go | 5 +- config/nacos/v2/client/retry.go | 5 +- config/nacos/v2/go.mod | 4 +- config/nacos/v2/utils/set.go | 46 ---- config/nacos/v2/utils/set_test.go | 42 ---- config/utils/go.mod | 21 ++ config/utils/parser.go | 69 ++++++ config/{apollo => }/utils/set.go | 32 ++- config/{nacos => }/utils/set_test.go | 0 config/zookeeper/client/circuit_breaker.go | 11 +- config/zookeeper/client/degradation.go | 7 +- config/zookeeper/client/retry.go | 11 +- config/zookeeper/client/rpc_timeout.go | 7 +- config/zookeeper/go.mod | 1 - config/zookeeper/server/limiter.go | 7 +- config/zookeeper/utils/set.go | 46 ---- config/zookeeper/zookeeper/parser.go | 26 -- .../consul/consulkitex/consul_registry.go | 18 +- registry/consul/options/option.go | 31 +++ registry/etcd/etcdhertz/Makefile | 3 +- registry/etcd/etcdhertz/etcd_test.go | 2 +- registry/etcd/etcdkitex/etcd_registry.go | 1 + registry/eureka/eurekakitex/entity/entity.go | 20 -- registry/polaris/go.sum | 40 --- registry/zookeeper/go.sum | 18 -- 63 files changed, 998 insertions(+), 720 deletions(-) delete mode 100644 config/consul/utils/set.go delete mode 100644 config/etcd/utils/set.go create mode 100644 config/file/filewatcher/filewatcher.go create mode 100644 config/file/mock/filewatcher_mock.go create mode 100644 config/file/monitor/monitor.go create mode 100644 config/file/monitor/monitor_test.go delete mode 100644 config/file/utils/set.go delete mode 100644 config/nacos/utils/set.go delete mode 100644 config/nacos/v2/utils/set.go delete mode 100644 config/nacos/v2/utils/set_test.go create mode 100644 config/utils/go.mod create mode 100644 config/utils/parser.go rename config/{apollo => }/utils/set.go (51%) rename config/{nacos => }/utils/set_test.go (100%) delete mode 100644 config/zookeeper/utils/set.go create mode 100644 registry/consul/options/option.go delete mode 100644 registry/eureka/eurekakitex/entity/entity.go diff --git a/config/apollo/apollo/apollo.go b/config/apollo/apollo/apollo.go index 697ff34..c809f3b 100644 --- a/config/apollo/apollo/apollo.go +++ b/config/apollo/apollo/apollo.go @@ -16,6 +16,7 @@ package apollo import ( "bytes" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "runtime/debug" "sync" "text/template" @@ -26,10 +27,10 @@ import ( // Client the wrapper of apollo client. type Client interface { - SetParser(ConfigParser) - ClientConfigParam(cpc *ConfigParamConfig) (ConfigParam, error) - ServerConfigParam(cpc *ConfigParamConfig) (ConfigParam, error) - RegisterConfigCallback(ConfigParam, func(string, ConfigParser), int64) + SetParser(cwutils.ConfigParser) + ClientConfigParam(cpc *cwutils.ConfigParamConfig) (ConfigParam, error) + ServerConfigParam(cpc *cwutils.ConfigParamConfig) (ConfigParam, error) + RegisterConfigCallback(ConfigParam, func(string, cwutils.ConfigParser), int64) DeregisterConfig(ConfigParam, int64) error } @@ -37,7 +38,7 @@ type ConfigParam struct { Key string nameSpace string Cluster string - Type ConfigType + Type cwutils.ConfigType } type callbackHandler func(namespace, cluster, key, data string) @@ -61,7 +62,7 @@ func getConfigParamKey(in *ConfigParam) configParamKey { type client struct { acli agollo.Agollo // support customise parser - parser ConfigParser + parser cwutils.ConfigParser stop chan bool clusterTemplate *template.Template serverKeyTemplate *template.Template @@ -87,7 +88,7 @@ type Options struct { ServerKeyFormat string ClientKeyFormat string ApolloOptions []agollo.Option - ConfigParser ConfigParser + ConfigParser cwutils.ConfigParser } type OptionFunc func(option *Options) @@ -97,7 +98,7 @@ func NewClient(opts Options, optsfunc ...OptionFunc) (Client, error) { opts.ConfigServerURL = ApolloDefaultConfigServerURL } if opts.ConfigParser == nil { - opts.ConfigParser = defaultConfigParse() + opts.ConfigParser = cwutils.DefaultConfigParse() } if opts.AppID == "" { opts.AppID = ApolloDefaultAppId @@ -154,11 +155,11 @@ func WithApolloOption(apolloOption ...agollo.Option) OptionFunc { } } -func (c *client) SetParser(parser ConfigParser) { +func (c *client) SetParser(parser cwutils.ConfigParser) { c.parser = parser } -func (c *client) render(cpc *ConfigParamConfig, t *template.Template) (string, error) { +func (c *client) render(cpc *cwutils.ConfigParamConfig, t *template.Template) (string, error) { var tpl bytes.Buffer err := t.Execute(&tpl, cpc) if err != nil { @@ -167,12 +168,12 @@ func (c *client) render(cpc *ConfigParamConfig, t *template.Template) (string, e return tpl.String(), nil } -func (c *client) ServerConfigParam(cpc *ConfigParamConfig) (ConfigParam, error) { +func (c *client) ServerConfigParam(cpc *cwutils.ConfigParamConfig) (ConfigParam, error) { return c.configParam(cpc, c.serverKeyTemplate) } // ClientConfigParam render client config parameters -func (c *client) ClientConfigParam(cpc *ConfigParamConfig) (ConfigParam, error) { +func (c *client) ClientConfigParam(cpc *cwutils.ConfigParamConfig) (ConfigParam, error) { return c.configParam(cpc, c.clientKeyTemplate) } @@ -180,13 +181,13 @@ func (c *client) ClientConfigParam(cpc *ConfigParamConfig) (ConfigParam, error) // ConfigParam explain: // 1. Type: key format, support JSON and YAML, JSON by default. Could extend it by implementing the ConfigParser interface. // 2. Content: empty by default. Customize with CustomFunction. -// 3. NameSpace: select by user (retry / circuit_breaker / rpc_timeout / limit). +// 3. nameSpace: select by user (retry / circuit_breaker / rpc_timeout / limit). // 4. ServerKey: {{.ServerServiceName}} by default. // ClientKey: {{.ClientServiceName}}.{{.ServerServiceName}} by default. // 5. Cluster: default by default -func (c *client) configParam(cpc *ConfigParamConfig, t *template.Template) (ConfigParam, error) { +func (c *client) configParam(cpc *cwutils.ConfigParamConfig, t *template.Template) (ConfigParam, error) { param := ConfigParam{ - Type: JSON, + Type: cwutils.JSON, nameSpace: cpc.Category, } var err error @@ -244,7 +245,7 @@ func (c *client) onChange(namespace, cluster, key, data string) { // RegisterConfigCallback register the callback function to apollo client. func (c *client) RegisterConfigCallback(param ConfigParam, - callback func(string, ConfigParser), uniqueID int64, + callback func(string, cwutils.ConfigParser), uniqueID int64, ) { onChange := func(namespace, cluster, key, data string) { klog.Debugf("[apollo] uniqueID %d config %s updated, namespace %s cluster %s key %s data %s", diff --git a/config/apollo/apollo/apollo_test.go b/config/apollo/apollo/apollo_test.go index cfb7dd9..3057de8 100644 --- a/config/apollo/apollo/apollo_test.go +++ b/config/apollo/apollo/apollo_test.go @@ -15,6 +15,7 @@ package apollo import ( + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "sync" "testing" "time" @@ -107,7 +108,7 @@ func TestRegisterAndDeregister(t *testing.T) { Key: "k1", nameSpace: "n1", Cluster: "c1", - }, func(s string, cp ConfigParser) { + }, func(s string, cp cwutils.ConfigParser) { gotlock.Lock() defer gotlock.Unlock() ids, ok := gots[configkey] @@ -133,7 +134,7 @@ func TestRegisterAndDeregister(t *testing.T) { Key: "k1", nameSpace: "n1", Cluster: "c1", - }, func(s string, cp ConfigParser) { + }, func(s string, cp cwutils.ConfigParser) { gotlock.Lock() defer gotlock.Unlock() klog.Info("onchange callback2:", s) diff --git a/config/apollo/apollo/parser.go b/config/apollo/apollo/parser.go index 710ab34..20c375c 100644 --- a/config/apollo/apollo/parser.go +++ b/config/apollo/apollo/parser.go @@ -14,62 +14,17 @@ package apollo -import ( - "fmt" - - "github.com/bytedance/sonic" -) - -// CustomFunction use for customize the config parameters. -type ( - CustomFunction func(*ConfigParam) - ConfigType string - ConfigContent string -) +type CustomFunction func(*ConfigParam) const ( - JSON ConfigType = "json" - YAML ConfigType = "yaml" - ApolloDefaultConfigServerURL = "127.0.0.1:8080" - ApolloDefaultAppId = "KitexApp" - ApolloDefaultCluster = "default" - ApolloNameSpace = "{{.Category}}" - ApolloDefaultClientKey = "{{.ClientServiceName}}.{{.ServerServiceName}}" - ApolloDefaultServerKey = "{{.ServerServiceName}}" + ApolloDefaultConfigServerURL = "127.0.0.1:8080" + ApolloDefaultAppId = "KitexApp" + ApolloDefaultCluster = "default" + ApolloNameSpace = "{{.Category}}" + ApolloDefaultClientKey = "{{.ClientServiceName}}.{{.ServerServiceName}}" + ApolloDefaultServerKey = "{{.ServerServiceName}}" ) const ( emptyConfig string = "{}" ) - -// ConfigParamConfig use for render the dataId or group info by go template, ref: https://pkg.go.dev/text/template -// The fixed key shows as below. -type ConfigParamConfig struct { - Category string - ClientServiceName string - ServerServiceName string -} - -var _ ConfigParser = &parser{} - -// ConfigParser the parser for Apollo config. -type ConfigParser interface { - Decode(kind ConfigType, data string, config interface{}) error -} - -type parser struct{} - -// Decode decodes the data to struct in specified format. -func (p *parser) Decode(kind ConfigType, data string, config interface{}) error { - switch kind { - case JSON: - return sonic.Unmarshal([]byte(data), config) - default: - return fmt.Errorf("unsupported config data type %s", kind) - } -} - -// DefaultConfigParse default apollo config parser. -func defaultConfigParse() ConfigParser { - return &parser{} -} diff --git a/config/apollo/client/circuit_breaker.go b/config/apollo/client/circuit_breaker.go index 82ab95d..62724a8 100644 --- a/config/apollo/client/circuit_breaker.go +++ b/config/apollo/client/circuit_breaker.go @@ -15,11 +15,11 @@ package client import ( + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "strings" "github.com/cloudwego-contrib/cwgo-pkg/config/apollo/apollo" "github.com/cloudwego-contrib/cwgo-pkg/config/apollo/utils" - "github.com/cloudwego/kitex/client" "github.com/cloudwego/kitex/pkg/circuitbreak" "github.com/cloudwego/kitex/pkg/klog" @@ -30,7 +30,7 @@ import ( func WithCircuitBreaker(dest, src string, apolloClient apollo.Client, opts utils.Options, ) []client.Option { - param, err := apolloClient.ClientConfigParam(&apollo.ConfigParamConfig{ + param, err := apolloClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: apollo.CircuitBreakerConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -83,10 +83,10 @@ func initCircuitBreaker(param apollo.ConfigParam, dest, src string, apolloClient apollo.Client, uniqueID int64, ) *circuitbreak.CBSuite { cb := circuitbreak.NewCBSuite(genServiceCBKeyWithRPCInfo) - lcb := utils.ThreadSafeSet{} + lcb := cwutils.ThreadSafeSet{} - onChangeCallback := func(data string, parser apollo.ConfigParser) { - set := utils.Set{} + onChangeCallback := func(data string, parser cwutils.ConfigParser) { + set := cwutils.Set{} configs := map[string]circuitbreak.CBConfig{} err := parser.Decode(param.Type, data, &configs) if err != nil { diff --git a/config/apollo/client/retry.go b/config/apollo/client/retry.go index b1cd40b..cde86a7 100644 --- a/config/apollo/client/retry.go +++ b/config/apollo/client/retry.go @@ -17,6 +17,7 @@ package client import ( "github.com/cloudwego-contrib/cwgo-pkg/config/apollo/apollo" "github.com/cloudwego-contrib/cwgo-pkg/config/apollo/utils" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego/kitex/client" "github.com/cloudwego/kitex/pkg/klog" "github.com/cloudwego/kitex/pkg/retry" @@ -25,7 +26,7 @@ import ( func WithRetryPolicy(dest, src string, apolloClient apollo.Client, opts utils.Options, ) []client.Option { - param, err := apolloClient.ClientConfigParam(&apollo.ConfigParamConfig{ + param, err := apolloClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: apollo.RetryConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -59,9 +60,9 @@ func initRetryContainer(param apollo.ConfigParam, dest string, ) *retry.Container { retryContainer := retry.NewRetryContainerWithPercentageLimit() - ts := utils.ThreadSafeSet{} + ts := cwutils.ThreadSafeSet{} - onChangeCallback := func(data string, parser apollo.ConfigParser) { + onChangeCallback := func(data string, parser cwutils.ConfigParser) { // the key is method name, wildcard "*" can match anything. rcs := map[string]*retry.Policy{} err := parser.Decode(param.Type, data, &rcs) @@ -70,7 +71,7 @@ func initRetryContainer(param apollo.ConfigParam, dest string, return } - set := utils.Set{} + set := cwutils.Set{} for method, policy := range rcs { set[method] = true if policy.BackupPolicy != nil && policy.FailurePolicy != nil { diff --git a/config/apollo/client/rpc_timetout.go b/config/apollo/client/rpc_timetout.go index e8d1922..032d8c0 100644 --- a/config/apollo/client/rpc_timetout.go +++ b/config/apollo/client/rpc_timetout.go @@ -17,6 +17,7 @@ package client import ( "github.com/cloudwego-contrib/cwgo-pkg/config/apollo/apollo" "github.com/cloudwego-contrib/cwgo-pkg/config/apollo/utils" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego/kitex/client" "github.com/cloudwego/kitex/pkg/klog" "github.com/cloudwego/kitex/pkg/rpcinfo" @@ -27,7 +28,7 @@ import ( func WithRPCTimeout(dest, src string, apolloClient apollo.Client, opts utils.Options, ) []client.Option { - param, err := apolloClient.ClientConfigParam(&apollo.ConfigParamConfig{ + param, err := apolloClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: apollo.RpcTimeoutConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -55,7 +56,7 @@ func initRPCTimeoutContainer(param apollo.ConfigParam, dest string, ) rpcinfo.TimeoutProvider { rpcTimeoutContainer := rpctimeout.NewContainer() - onChangeCallback := func(data string, parser apollo.ConfigParser) { + onChangeCallback := func(data string, parser cwutils.ConfigParser) { configs := map[string]*rpctimeout.RPCTimeout{} err := parser.Decode(param.Type, data, &configs) if err != nil { diff --git a/config/apollo/client/suite.go b/config/apollo/client/suite.go index 066335a..fac51b5 100644 --- a/config/apollo/client/suite.go +++ b/config/apollo/client/suite.go @@ -15,13 +15,13 @@ package client import ( - "github.com/cloudwego-contrib/cwgo-pkg/config/apollo/apollo" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/apollo/apollo" "github.com/cloudwego-contrib/cwgo-pkg/config/apollo/utils" "github.com/cloudwego/kitex/client" ) type ApolloClientSuite struct { - apolloClient apollo.Client + apolloClient cwutils.Client service string client string opts utils.Options @@ -29,7 +29,7 @@ type ApolloClientSuite struct { type ClientSuiteOption func(*ApolloClientSuite) -func NewSuite(service, client string, cli apollo.Client, +func NewSuite(service, client string, cli cwutils.Client, options ...utils.Option, ) *ApolloClientSuite { client_suite := &ApolloClientSuite{ diff --git a/config/apollo/go.mod b/config/apollo/go.mod index 34c8622..a5c1491 100644 --- a/config/apollo/go.mod +++ b/config/apollo/go.mod @@ -10,6 +10,7 @@ require ( github.com/shima-park/agollo v1.2.14 go.uber.org/atomic v1.11.0 gopkg.in/go-playground/assert.v1 v1.2.1 + ) require ( diff --git a/config/apollo/server/limiter.go b/config/apollo/server/limiter.go index 51dcd19..e2c732f 100644 --- a/config/apollo/server/limiter.go +++ b/config/apollo/server/limiter.go @@ -15,6 +15,7 @@ package server import ( + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "sync/atomic" "github.com/cloudwego/kitex/pkg/klog" @@ -30,7 +31,7 @@ import ( func WithLimiter(dest string, apolloClient apollo.Client, opts utils.Options, ) server.Option { - param, err := apolloClient.ServerConfigParam(&apollo.ConfigParamConfig{ + param, err := apolloClient.ServerConfigParam(&cwutils.ConfigParamConfig{ Category: apollo.LimiterConfigName, ServerServiceName: dest, }) @@ -55,7 +56,7 @@ func initLimitOptions(param apollo.ConfigParam, dest string, apolloClient apollo u.UpdateLimit(opt) updater.Store(u) } - onChangeCallback := func(data string, parser apollo.ConfigParser) { + onChangeCallback := func(data string, parser cwutils.ConfigParser) { lc := &limiter.LimiterConfig{} err := parser.Decode(param.Type, data, lc) if err != nil { diff --git a/config/consul/client/circult_breaker.go b/config/consul/client/circult_breaker.go index 3b33d4c..ca6df78 100644 --- a/config/consul/client/circult_breaker.go +++ b/config/consul/client/circult_breaker.go @@ -15,6 +15,7 @@ package client import ( + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "strings" "github.com/cloudwego-contrib/cwgo-pkg/config/consul/consul" @@ -28,7 +29,7 @@ import ( // WithCircuitBreaker sets the circuit breaker policy from consul configuration center. func WithCircuitBreaker(dest, src string, consulClient consul.Client, uniqueID int64, opts utils.Options) []client.Option { - param, err := consulClient.ClientConfigParam(&consul.ConfigParamConfig{ + param, err := consulClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: circuitBreakerConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -76,14 +77,14 @@ func genServiceCBKey(toService, method string) string { return buf.String() } -func initCircuitBreaker(configType consul.ConfigType, key, dest, src string, +func initCircuitBreaker(configType cwutils.ConfigType, key, dest, src string, consulClient consul.Client, uniqueID int64, ) *circuitbreak.CBSuite { cb := circuitbreak.NewCBSuite(genServiceCBKeyWithRPCInfo) - lcb := utils.ThreadSafeSet{} + lcb := cwutils.ThreadSafeSet{} - onChangeCallback := func(data string, parser consul.ConfigParser) { - set := utils.Set{} + onChangeCallback := func(data string, parser cwutils.ConfigParser) { + set := cwutils.Set{} configs := map[string]circuitbreak.CBConfig{} err := parser.Decode(configType, data, &configs) if err != nil { diff --git a/config/consul/client/degradation.go b/config/consul/client/degradation.go index d8d14c1..51bd0d4 100644 --- a/config/consul/client/degradation.go +++ b/config/consul/client/degradation.go @@ -18,12 +18,13 @@ import ( "github.com/cloudwego-contrib/cwgo-pkg/config/consul/consul" "github.com/cloudwego-contrib/cwgo-pkg/config/consul/pkg/degradation" "github.com/cloudwego-contrib/cwgo-pkg/config/consul/utils" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego/kitex/client" "github.com/cloudwego/kitex/pkg/klog" ) func WithDegradation(dest, src string, consulClient consul.Client, uniqueID int64, opts utils.Options) []client.Option { - param, err := consulClient.ClientConfigParam(&consul.ConfigParamConfig{ + param, err := consulClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: degradationConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -46,9 +47,9 @@ func WithDegradation(dest, src string, consulClient consul.Client, uniqueID int6 } } -func initDegradationOptions(configType consul.ConfigType, key, dest string, uniqueID int64, consulClient consul.Client) *degradation.DegradationContainer { +func initDegradationOptions(configType cwutils.ConfigType, key, dest string, uniqueID int64, consulClient consul.Client) *degradation.DegradationContainer { container := degradation.NewDegradationContainer() - onChangeCallback := func(data string, parser consul.ConfigParser) { + onChangeCallback := func(data string, parser cwutils.ConfigParser) { config := °radation.DegradationConfig{} err := parser.Decode(configType, data, config) if err != nil { diff --git a/config/consul/client/retry.go b/config/consul/client/retry.go index 522c913..0150d8d 100644 --- a/config/consul/client/retry.go +++ b/config/consul/client/retry.go @@ -17,6 +17,7 @@ package client import ( "github.com/cloudwego-contrib/cwgo-pkg/config/consul/consul" "github.com/cloudwego-contrib/cwgo-pkg/config/consul/utils" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego/kitex/client" "github.com/cloudwego/kitex/pkg/klog" @@ -25,7 +26,7 @@ import ( // WithRetryPolicy sets the retry policy from consul configuration center. func WithRetryPolicy(dest, src string, consulClient consul.Client, uniqueID int64, opts utils.Options) []client.Option { - param, err := consulClient.ClientConfigParam(&consul.ConfigParamConfig{ + param, err := consulClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: retryConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -50,14 +51,14 @@ func WithRetryPolicy(dest, src string, consulClient consul.Client, uniqueID int6 } } -func initRetryContainer(configType consul.ConfigType, key, dest string, +func initRetryContainer(configType cwutils.ConfigType, key, dest string, consulClient consul.Client, uniqueID int64, ) *retry.Container { retryContainer := retry.NewRetryContainerWithPercentageLimit() - ts := utils.ThreadSafeSet{} + ts := cwutils.ThreadSafeSet{} - onChangeCallback := func(data string, parser consul.ConfigParser) { + onChangeCallback := func(data string, parser cwutils.ConfigParser) { // the key is method name, wildcard "*" can match anything. rcs := map[string]*retry.Policy{} err := parser.Decode(configType, data, &rcs) @@ -65,7 +66,7 @@ func initRetryContainer(configType consul.ConfigType, key, dest string, klog.Warnf("[consul] %s client consul retry: unmarshal data %s failed: %s, skip...", key, data, err) return } - set := utils.Set{} + set := cwutils.Set{} for method, policy := range rcs { set[method] = true if policy.Enable && policy.BackupPolicy == nil && policy.FailurePolicy == nil { diff --git a/config/consul/client/rpc_timeout.go b/config/consul/client/rpc_timeout.go index a66b88a..71ec14f 100644 --- a/config/consul/client/rpc_timeout.go +++ b/config/consul/client/rpc_timeout.go @@ -17,6 +17,7 @@ package client import ( "github.com/cloudwego-contrib/cwgo-pkg/config/consul/consul" "github.com/cloudwego-contrib/cwgo-pkg/config/consul/utils" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego/kitex/client" "github.com/cloudwego/kitex/pkg/klog" @@ -26,7 +27,7 @@ import ( // WithRPCTimeout sets the RPC timeout policy from consul configuration center. func WithRPCTimeout(dest, src string, consulClient consul.Client, uniqueID int64, opts utils.Options) []client.Option { - param, err := consulClient.ClientConfigParam(&consul.ConfigParamConfig{ + param, err := consulClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: rpcTimeoutConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -49,12 +50,12 @@ func WithRPCTimeout(dest, src string, consulClient consul.Client, uniqueID int64 } } -func initRPCTimeoutContainer(configType consul.ConfigType, key, dest string, +func initRPCTimeoutContainer(configType cwutils.ConfigType, key, dest string, consulClient consul.Client, uniqueID int64, ) rpcinfo.TimeoutProvider { rpcTimeoutContainer := rpctimeout.NewContainer() - onChangeCallback := func(data string, parser consul.ConfigParser) { + onChangeCallback := func(data string, parser cwutils.ConfigParser) { configs := map[string]*rpctimeout.RPCTimeout{} err := parser.Decode(configType, data, &configs) if err != nil { diff --git a/config/consul/consul/consul.go b/config/consul/consul/consul.go index d89b384..5ffb90b 100644 --- a/config/consul/consul/consul.go +++ b/config/consul/consul/consul.go @@ -17,6 +17,7 @@ package consul import ( "bytes" "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "html/template" "strconv" "sync" @@ -31,7 +32,7 @@ import ( const WatchByKey = "key" type Key struct { - Type ConfigType + Type cwutils.ConfigType Prefix string Path string } @@ -45,10 +46,10 @@ type ListenConfig struct { Partition string } type Client interface { - SetParser(configParser ConfigParser) - ClientConfigParam(cpc *ConfigParamConfig, cfs ...CustomFunction) (Key, error) - ServerConfigParam(cpc *ConfigParamConfig, cfs ...CustomFunction) (Key, error) - RegisterConfigCallback(key string, uniqueID int64, callback func(string, ConfigParser)) + SetParser(configParser cwutils.ConfigParser) + ClientConfigParam(cpc *cwutils.ConfigParamConfig, cfs ...CustomFunction) (Key, error) + ServerConfigParam(cpc *cwutils.ConfigParamConfig, cfs ...CustomFunction) (Key, error) + RegisterConfigCallback(key string, uniqueID int64, callback func(string, cwutils.ConfigParser)) DeregisterConfig(key string, uniqueID int64) } @@ -63,13 +64,13 @@ type Options struct { Token string Partition string LoggerConfig *zap.Config - ConfigParser ConfigParser + ConfigParser cwutils.ConfigParser } type client struct { consulCli *api.Client lconfig *ListenConfig - parser ConfigParser + parser cwutils.ConfigParser consulTimeout time.Duration prefixTemplate *template.Template serverPathTemplate *template.Template @@ -86,7 +87,7 @@ func NewClient(opts Options) (Client, error) { opts.Prefix = ConsulDefaultConfiGPrefix } if opts.ConfigParser == nil { - opts.ConfigParser = defaultConfigParse() + opts.ConfigParser = cwutils.DefaultConfigParse() } if opts.TimeOut == 0 { opts.TimeOut = ConsulDefaultTimeout @@ -144,15 +145,15 @@ func NewClient(opts Options) (Client, error) { } // SetParser support customise parser -func (c *client) SetParser(parser ConfigParser) { +func (c *client) SetParser(parser cwutils.ConfigParser) { c.parser = parser } -func (c *client) ClientConfigParam(cpc *ConfigParamConfig, cfs ...CustomFunction) (Key, error) { +func (c *client) ClientConfigParam(cpc *cwutils.ConfigParamConfig, cfs ...CustomFunction) (Key, error) { return c.configParam(cpc, c.clientPathTemplate, cfs...) } -func (c *client) ServerConfigParam(cpc *ConfigParamConfig, cfs ...CustomFunction) (Key, error) { +func (c *client) ServerConfigParam(cpc *cwutils.ConfigParamConfig, cfs ...CustomFunction) (Key, error) { return c.configParam(cpc, c.serverPathTemplate, cfs...) } @@ -161,8 +162,8 @@ func (c *client) ServerConfigParam(cpc *ConfigParamConfig, cfs ...CustomFunction // 1. Prefix: KitexConfig by default. // 2. ServerPath: {{.ServerServiceName}}/{{.Category}} by default. // ClientPath: {{.ClientServiceName}}/{{.ServerServiceName}}/{{.Category}} by default. -func (c *client) configParam(cpc *ConfigParamConfig, t *template.Template, cfs ...CustomFunction) (Key, error) { - param := Key{Type: JSON} +func (c *client) configParam(cpc *cwutils.ConfigParamConfig, t *template.Template, cfs ...CustomFunction) (Key, error) { + param := Key{Type: cwutils.JSON} var err error param.Path, err = c.render(cpc, t) if err != nil { @@ -179,7 +180,7 @@ func (c *client) configParam(cpc *ConfigParamConfig, t *template.Template, cfs . return param, nil } -func (c *client) render(cpc *ConfigParamConfig, t *template.Template) (string, error) { +func (c *client) render(cpc *cwutils.ConfigParamConfig, t *template.Template) (string, error) { var tpl bytes.Buffer err := t.Execute(&tpl, cpc) if err != nil { @@ -189,7 +190,7 @@ func (c *client) render(cpc *ConfigParamConfig, t *template.Template) (string, e } // RegisterConfigCallback register the callback function to consul client. -func (c *client) RegisterConfigCallback(key string, uniqueID int64, callback func(string, ConfigParser)) { +func (c *client) RegisterConfigCallback(key string, uniqueID int64, callback func(string, cwutils.ConfigParser)) { go func() { clientCtx, cancel := context.WithCancel(context.Background()) params := make(map[string]interface{}) diff --git a/config/consul/consul/parser.go b/config/consul/consul/parser.go index 8cd20b0..4a81f9a 100644 --- a/config/consul/consul/parser.go +++ b/config/consul/consul/parser.go @@ -15,54 +15,16 @@ package consul import ( - "encoding/json" - "fmt" "time" - - yaml "sigs.k8s.io/yaml/goyaml.v3" ) -type ConfigType string +type CustomFunction func(*Key) const ( - JSON ConfigType = "json" - YAML ConfigType = "yaml" - HCL ConfigType = "hcl" - ConsulDefaultConfigAddr = "127.0.0.1:8500" - ConsulDefaultConfiGPrefix = "KitexConfig" - ConsulDefaultTimeout = 5 * time.Second - ConsulDefaultDataCenter = "dc1" - ConsulDefaultClientPath = "{{.ClientServiceName}}/{{.ServerServiceName}}/{{.Category}}" - ConsulDefaultServerPath = "{{.ServerServiceName}}/{{.Category}}" + ConsulDefaultConfigAddr = "127.0.0.1:8500" + ConsulDefaultConfiGPrefix = "KitexConfig" + ConsulDefaultTimeout = 5 * time.Second + ConsulDefaultDataCenter = "dc1" + ConsulDefaultClientPath = "{{.ClientServiceName}}/{{.ServerServiceName}}/{{.Category}}" + ConsulDefaultServerPath = "{{.ServerServiceName}}/{{.Category}}" ) - -var _ ConfigParser = &parser{} - -// CustomFunction use for customize the config parameters. -type CustomFunction func(*Key) - -type ConfigParamConfig struct { - Category string - ClientServiceName string - ServerServiceName string -} - -type ConfigParser interface { - Decode(configType ConfigType, data string, config interface{}) error -} -type parser struct{} - -func (p *parser) Decode(configType ConfigType, data string, config interface{}) error { - switch configType { - case JSON: - return json.Unmarshal([]byte(data), config) - case YAML: - return yaml.Unmarshal([]byte(data), config) - default: - return fmt.Errorf("unsupported config data type %s", configType) - } -} - -func defaultConfigParse() ConfigParser { - return &parser{} -} diff --git a/config/consul/go.mod b/config/consul/go.mod index e36206e..f786327 100644 --- a/config/consul/go.mod +++ b/config/consul/go.mod @@ -1,10 +1,14 @@ module github.com/cloudwego-contrib/cwgo-pkg/config/consul -go 1.20 +go 1.21 + require ( + github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b + github.com/cloudwego/configmanager v0.2.0 github.com/cloudwego/kitex v0.8.0 github.com/cloudwego/kitex-examples v0.2.4 + github.com/cloudwego/thriftgo v0.3.3 github.com/hashicorp/consul/api v1.26.1 go.uber.org/zap v1.26.0 sigs.k8s.io/yaml v1.4.0 @@ -13,18 +17,15 @@ require ( require ( github.com/apache/thrift v0.16.0 // indirect github.com/armon/go-metrics v0.4.1 // indirect - github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b // indirect github.com/bytedance/sonic v1.10.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect github.com/chenzhuoyu/iasm v0.9.1 // indirect github.com/choleraehyq/pid v0.0.17 // indirect - github.com/cloudwego/configmanager v0.2.0 // indirect github.com/cloudwego/dynamicgo v0.1.6 // indirect github.com/cloudwego/fastpb v0.0.4 // indirect github.com/cloudwego/frugal v0.1.12 // indirect github.com/cloudwego/localsession v0.0.2 // indirect github.com/cloudwego/netpoll v0.5.1 // indirect - github.com/cloudwego/thriftgo v0.3.3 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fatih/color v1.16.0 // indirect github.com/fatih/structtag v1.2.0 // indirect diff --git a/config/consul/server/limiter.go b/config/consul/server/limiter.go index b2f50de..fb2e5a9 100644 --- a/config/consul/server/limiter.go +++ b/config/consul/server/limiter.go @@ -15,6 +15,7 @@ package server import ( + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "sync/atomic" "github.com/cloudwego-contrib/cwgo-pkg/config/consul/consul" @@ -28,7 +29,7 @@ import ( // WithLimiter sets the limiter config from consul configuration center. func WithLimiter(dest string, consulClient consul.Client, uniqueID int64, opts utils.Options) server.Option { - param, err := consulClient.ServerConfigParam(&consul.ConfigParamConfig{ + param, err := consulClient.ServerConfigParam(&cwutils.ConfigParamConfig{ Category: limiterConfigName, ServerServiceName: dest, }) @@ -45,7 +46,7 @@ func WithLimiter(dest string, consulClient consul.Client, uniqueID int64, opts u return server.WithLimit(initLimitOptions(param.Type, key, uniqueID, consulClient)) } -func initLimitOptions(kind consul.ConfigType, key string, uniqueID int64, consulClient consul.Client) *limit.Option { +func initLimitOptions(kind cwutils.ConfigType, key string, uniqueID int64, consulClient consul.Client) *limit.Option { var updater atomic.Value opt := &limit.Option{} opt.UpdateControl = func(u limit.Updater) { @@ -53,7 +54,7 @@ func initLimitOptions(kind consul.ConfigType, key string, uniqueID int64, consul u.UpdateLimit(opt) updater.Store(u) } - onChangeCallback := func(data string, parser consul.ConfigParser) { + onChangeCallback := func(data string, parser cwutils.ConfigParser) { lc := &limiter.LimiterConfig{} err := parser.Decode(kind, data, lc) diff --git a/config/consul/utils/set.go b/config/consul/utils/set.go deleted file mode 100644 index 7b7cb3c..0000000 --- a/config/consul/utils/set.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2024 CloudWeGo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils - -import "sync" - -// ThreadSafeSet wrapper of Set. -type ThreadSafeSet struct { - sync.RWMutex - s Set -} - -// DiffAndEmplace returns the keys that are not in other and emplace the old set. -func (ts *ThreadSafeSet) DiffAndEmplace(other Set) []string { - ts.Lock() - defer ts.Unlock() - out := ts.s.Diff(other) - ts.s = other - return out -} - -// Set map template. -type Set map[string]bool - -// Diff returns the keys that are not in other -func (s Set) Diff(other Set) []string { - out := make([]string, 0, len(s)) - for key := range s { - if _, ok := other[key]; !ok { - out = append(out, key) - } - } - return out -} diff --git a/config/etcd/client/circuit_breaker.go b/config/etcd/client/circuit_breaker.go index d6bc58e..85863d5 100644 --- a/config/etcd/client/circuit_breaker.go +++ b/config/etcd/client/circuit_breaker.go @@ -16,6 +16,7 @@ package client import ( "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "strings" "github.com/cloudwego/kitex/pkg/klog" @@ -29,7 +30,7 @@ import ( // WithCircuitBreaker sets the circuit breaker policy from etcd configuration center. func WithCircuitBreaker(dest, src string, etcdClient etcd.Client, uniqueID int64, opts utils.Options) []client.Option { - param, err := etcdClient.ClientConfigParam(&etcd.ConfigParamConfig{ + param, err := etcdClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: circuitBreakerConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -81,14 +82,14 @@ func initCircuitBreaker(key, dest, src string, etcdClient etcd.Client, uniqueID int64, ) *circuitbreak.CBSuite { cb := circuitbreak.NewCBSuite(genServiceCBKeyWithRPCInfo) - lcb := utils.ThreadSafeSet{} + lcb := cwutils.ThreadSafeSet{} - onChangeCallback := func(restoreDefault bool, data string, parser etcd.ConfigParser) { - set := utils.Set{} + onChangeCallback := func(restoreDefault bool, data string, parser cwutils.ConfigParser) { + set := cwutils.Set{} configs := map[string]circuitbreak.CBConfig{} if !restoreDefault { - err := parser.Decode(data, &configs) + err := parser.Decode(cwutils.JSON, data, &configs) if err != nil { klog.Warnf("[etcd] %s client etcd circuit breaker: unmarshal data %s failed: %s, skip...", key, data, err) return diff --git a/config/etcd/client/degradation.go b/config/etcd/client/degradation.go index 407fb1e..d03048f 100644 --- a/config/etcd/client/degradation.go +++ b/config/etcd/client/degradation.go @@ -16,6 +16,7 @@ package client import ( "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego-contrib/cwgo-pkg/config/etcd/etcd" "github.com/cloudwego-contrib/cwgo-pkg/config/etcd/pkg/degradation" @@ -26,7 +27,7 @@ import ( ) func WithDegradation(dest, src string, etcdClient etcd.Client, uniqueID int64, opts utils.Options) []client.Option { - param, err := etcdClient.ClientConfigParam(&etcd.ConfigParamConfig{ + param, err := etcdClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: degradationConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -51,10 +52,10 @@ func WithDegradation(dest, src string, etcdClient etcd.Client, uniqueID int64, o func initDegradationOptions(key, dest string, uniqueID int64, etcdClient etcd.Client) *degradation.Container { container := degradation.NewContainer() - onChangeCallback := func(restoreDefault bool, data string, parser etcd.ConfigParser) { + onChangeCallback := func(restoreDefault bool, data string, parser cwutils.ConfigParser) { config := °radation.Config{} if !restoreDefault { - err := parser.Decode(data, config) + err := parser.Decode(cwutils.JSON, data, config) if err != nil { klog.Warnf("[etcd] %s server etcd degradation config: unmarshal data %s failed: %s, skip...", key, data, err) return diff --git a/config/etcd/client/retry.go b/config/etcd/client/retry.go index 8949206..8923488 100644 --- a/config/etcd/client/retry.go +++ b/config/etcd/client/retry.go @@ -16,6 +16,7 @@ package client import ( "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego-contrib/cwgo-pkg/config/etcd/etcd" "github.com/cloudwego-contrib/cwgo-pkg/config/etcd/utils" @@ -26,7 +27,7 @@ import ( // WithRetryPolicy sets the retry policy from etcd configuration center. func WithRetryPolicy(dest, src string, etcdClient etcd.Client, uniqueID int64, opts utils.Options) []client.Option { - param, err := etcdClient.ClientConfigParam(&etcd.ConfigParamConfig{ + param, err := etcdClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: retryConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -56,21 +57,21 @@ func initRetryContainer(key, dest string, ) *retry.Container { retryContainer := retry.NewRetryContainerWithPercentageLimit() - ts := utils.ThreadSafeSet{} + ts := cwutils.ThreadSafeSet{} - onChangeCallback := func(restoreDefault bool, data string, parser etcd.ConfigParser) { + onChangeCallback := func(restoreDefault bool, data string, parser cwutils.ConfigParser) { // the key is method name, wildcard "*" can match anything. rcs := map[string]*retry.Policy{} if !restoreDefault { - err := parser.Decode(data, &rcs) + err := parser.Decode(cwutils.JSON, data, &rcs) if err != nil { klog.Warnf("[etcd] %s client etcd retry: unmarshal data %s failed: %s, skip...", key, data, err) return } } - set := utils.Set{} + set := cwutils.Set{} for method, policy := range rcs { set[method] = true if policy.Enable && policy.BackupPolicy == nil && policy.FailurePolicy == nil { diff --git a/config/etcd/client/rpc_timeout.go b/config/etcd/client/rpc_timeout.go index 615740a..2c793fb 100644 --- a/config/etcd/client/rpc_timeout.go +++ b/config/etcd/client/rpc_timeout.go @@ -16,6 +16,7 @@ package client import ( "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego-contrib/cwgo-pkg/config/etcd/etcd" "github.com/cloudwego-contrib/cwgo-pkg/config/etcd/utils" @@ -27,7 +28,7 @@ import ( // WithRPCTimeout sets the RPC timeout policy from etcd configuration center. func WithRPCTimeout(dest, src string, etcdClient etcd.Client, uniqueID int64, opts utils.Options) []client.Option { - param, err := etcdClient.ClientConfigParam(&etcd.ConfigParamConfig{ + param, err := etcdClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: rpcTimeoutConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -55,10 +56,10 @@ func initRPCTimeoutContainer(key, dest string, ) rpcinfo.TimeoutProvider { rpcTimeoutContainer := rpctimeout.NewContainer() - onChangeCallback := func(restoreDefault bool, data string, parser etcd.ConfigParser) { + onChangeCallback := func(restoreDefault bool, data string, parser cwutils.ConfigParser) { configs := map[string]*rpctimeout.RPCTimeout{} if !restoreDefault { - err := parser.Decode(data, &configs) + err := parser.Decode(cwutils.JSON, data, &configs) if err != nil { klog.Warnf("[etcd] %s client etcd rpc timeout: unmarshal data %s failed: %s, skip...", key, data, err) return diff --git a/config/etcd/etcd/etcd.go b/config/etcd/etcd/etcd.go index 16941ee..6838c13 100644 --- a/config/etcd/etcd/etcd.go +++ b/config/etcd/etcd/etcd.go @@ -17,6 +17,7 @@ package etcd import ( "bytes" "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "strconv" "sync" "text/template" @@ -36,17 +37,17 @@ type Key struct { } type Client interface { - SetParser(ConfigParser) - ClientConfigParam(cpc *ConfigParamConfig, cfs ...CustomFunction) (Key, error) - ServerConfigParam(cpc *ConfigParamConfig, cfs ...CustomFunction) (Key, error) - RegisterConfigCallback(ctx context.Context, key string, clientId int64, callback func(restoreDefault bool, data string, parser ConfigParser)) + SetParser(cwutils.ConfigParser) + ClientConfigParam(cpc *cwutils.ConfigParamConfig, cfs ...CustomFunction) (Key, error) + ServerConfigParam(cpc *cwutils.ConfigParamConfig, cfs ...CustomFunction) (Key, error) + RegisterConfigCallback(ctx context.Context, key string, clientId int64, callback func(restoreDefault bool, data string, parser cwutils.ConfigParser)) DeregisterConfig(key string, uniqueId int64) } type client struct { ecli *clientv3.Client // support customise parser - parser ConfigParser + parser cwutils.ConfigParser etcdTimeout time.Duration prefixTemplate *template.Template serverPathTemplate *template.Template @@ -63,7 +64,7 @@ type Options struct { ClientPathFormat string Timeout time.Duration LoggerConfig *zap.Config - ConfigParser ConfigParser + ConfigParser cwutils.ConfigParser } // NewClient Create a default etcd client @@ -74,7 +75,7 @@ func NewClient(opts Options) (Client, error) { opts.Node = []string{EtcdDefaultNode} } if opts.ConfigParser == nil { - opts.ConfigParser = defaultConfigParse() + opts.ConfigParser = cwutils.DefaultConfigParse() } if opts.Prefix == "" { opts.Prefix = EtcdDefaultConfigPrefix @@ -119,15 +120,15 @@ func NewClient(opts Options) (Client, error) { return c, nil } -func (c *client) SetParser(parser ConfigParser) { +func (c *client) SetParser(parser cwutils.ConfigParser) { c.parser = parser } -func (c *client) ClientConfigParam(cpc *ConfigParamConfig, cfs ...CustomFunction) (Key, error) { +func (c *client) ClientConfigParam(cpc *cwutils.ConfigParamConfig, cfs ...CustomFunction) (Key, error) { return c.configParam(cpc, c.clientPathTemplate, cfs...) } -func (c *client) ServerConfigParam(cpc *ConfigParamConfig, cfs ...CustomFunction) (Key, error) { +func (c *client) ServerConfigParam(cpc *cwutils.ConfigParamConfig, cfs ...CustomFunction) (Key, error) { return c.configParam(cpc, c.serverPathTemplate, cfs...) } @@ -136,7 +137,7 @@ func (c *client) ServerConfigParam(cpc *ConfigParamConfig, cfs ...CustomFunction // 1. Prefix: KitexConfig by default. // 2. ServerPath: {{.ServerServiceName}}/{{.Category}} by default. // ClientPath: {{.ClientServiceName}}/{{.ServerServiceName}}/{{.Category}} by default. -func (c *client) configParam(cpc *ConfigParamConfig, t *template.Template, cfs ...CustomFunction) (Key, error) { +func (c *client) configParam(cpc *cwutils.ConfigParamConfig, t *template.Template, cfs ...CustomFunction) (Key, error) { param := Key{} var err error @@ -155,7 +156,7 @@ func (c *client) configParam(cpc *ConfigParamConfig, t *template.Template, cfs . return param, nil } -func (c *client) render(cpc *ConfigParamConfig, t *template.Template) (string, error) { +func (c *client) render(cpc *cwutils.ConfigParamConfig, t *template.Template) (string, error) { var tpl bytes.Buffer err := t.Execute(&tpl, cpc) if err != nil { @@ -165,7 +166,7 @@ func (c *client) render(cpc *ConfigParamConfig, t *template.Template) (string, e } // RegisterConfigCallback register the callback function to etcd client. -func (c *client) RegisterConfigCallback(ctx context.Context, key string, uniqueID int64, callback func(bool, string, ConfigParser)) { +func (c *client) RegisterConfigCallback(ctx context.Context, key string, uniqueID int64, callback func(bool, string, cwutils.ConfigParser)) { go func() { clientCtx, cancel := context.WithCancel(context.Background()) c.registerCancelFunc(key, uniqueID, cancel) diff --git a/config/etcd/etcd/parser.go b/config/etcd/etcd/parser.go index 91dbef2..19c31db 100644 --- a/config/etcd/etcd/parser.go +++ b/config/etcd/etcd/parser.go @@ -15,7 +15,6 @@ package etcd import ( - "encoding/json" "time" ) @@ -27,32 +26,5 @@ const ( EtcdDefaultServerPath = "{{.ServerServiceName}}/{{.Category}}" ) -var _ ConfigParser = &parser{} - // CustomFunction use for customize the config parameters. type CustomFunction func(*Key) - -// ConfigParamConfig use for render the path or prefix info by go template, ref: https://pkg.go.dev/text/template -// The fixed key shows as below. -type ConfigParamConfig struct { - Category string - ClientServiceName string - ServerServiceName string -} - -// ConfigParser the parser for etcd config. -type ConfigParser interface { - Decode(data string, config interface{}) error -} - -type parser struct{} - -// Decode decodes the data to struct in specified format. -func (p *parser) Decode(data string, config interface{}) error { - return json.Unmarshal([]byte(data), config) -} - -// DefaultConfigParse default etcd config parser. -func defaultConfigParse() ConfigParser { - return &parser{} -} diff --git a/config/etcd/go.mod b/config/etcd/go.mod index c52a430..dd53671 100644 --- a/config/etcd/go.mod +++ b/config/etcd/go.mod @@ -2,8 +2,6 @@ module github.com/cloudwego-contrib/cwgo-pkg/config/etcd go 1.21 - - require ( github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b github.com/cloudwego/configmanager v0.2.0 diff --git a/config/etcd/server/limiter.go b/config/etcd/server/limiter.go index d00b612..c1a5669 100644 --- a/config/etcd/server/limiter.go +++ b/config/etcd/server/limiter.go @@ -16,6 +16,7 @@ package server import ( "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "sync/atomic" "github.com/cloudwego-contrib/cwgo-pkg/config/etcd/utils" @@ -30,7 +31,7 @@ import ( // WithLimiter sets the limiter config from etcd configuration center. func WithLimiter(dest string, etcdClient etcd.Client, uniqueID int64, opts utils.Options) server.Option { - param, err := etcdClient.ServerConfigParam(&etcd.ConfigParamConfig{ + param, err := etcdClient.ServerConfigParam(&cwutils.ConfigParamConfig{ Category: limiterConfigName, ServerServiceName: dest, }) @@ -55,11 +56,11 @@ func initLimitOptions(key string, uniqueID int64, etcdClient etcd.Client) *limit u.UpdateLimit(opt) updater.Store(u) } - onChangeCallback := func(restoreDefault bool, data string, parser etcd.ConfigParser) { + onChangeCallback := func(restoreDefault bool, data string, parser cwutils.ConfigParser) { lc := &limiter.LimiterConfig{} if !restoreDefault { - err := parser.Decode(data, lc) + err := parser.Decode(cwutils.JSON, data, lc) if err != nil { klog.Warnf("[etcd] %s server etcd limiter config: unmarshal data %s failed: %s, skip...", key, data, err) return diff --git a/config/etcd/utils/set.go b/config/etcd/utils/set.go deleted file mode 100644 index 597f225..0000000 --- a/config/etcd/utils/set.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2023 CloudWeGo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils - -import "sync" - -// ThreadSafeSet wrapper of Set. -type ThreadSafeSet struct { - sync.RWMutex - s Set -} - -// DiffAndEmplace returns the keys that are not in other and emplace the old set. -func (ts *ThreadSafeSet) DiffAndEmplace(other Set) []string { - ts.Lock() - defer ts.Unlock() - out := ts.s.Diff(other) - ts.s = other - return out -} - -// Set map template. -type Set map[string]bool - -// Diff returns the keys that are not in other -func (s Set) Diff(other Set) []string { - out := make([]string, 0, len(s)) - for key := range s { - if _, ok := other[key]; !ok { - out = append(out, key) - } - } - return out -} diff --git a/config/file/filewatcher/filewatcher.go b/config/file/filewatcher/filewatcher.go new file mode 100644 index 0000000..e43b9f6 --- /dev/null +++ b/config/file/filewatcher/filewatcher.go @@ -0,0 +1,205 @@ +// Copyright 2024 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package filewatcher + +import ( + "errors" + "os" + "strconv" + "sync" + "sync/atomic" + + "github.com/cloudwego-contrib/cwgo-pkg/config/file/utils" + "github.com/cloudwego/kitex/pkg/klog" + "github.com/fsnotify/fsnotify" +) + +type FileWatcher interface { + FilePath() string + CallbackSize() int + RegisterCallback(callback func(data []byte)) int64 + DeregisterCallback(uniqueID int64) + StartWatching() error + StopWatching() + CallOnceAll() error + CallOnceSpecific(uniqueID int64) error +} + +// FileWatcher is used for file monitoring +type fileWatcher struct { + filePath string // The path to the file to be monitored. + callbacks map[int64]func(data []byte) // Custom functions to be executed when the file changes. + watcher *fsnotify.Watcher // fsnotify file change watcher. + done chan struct{} // A channel for signaling the watcher to stop. + lock sync.RWMutex // mutex + counter atomic.Int64 // unique id for callbacks, only increase +} + +// NewFileWatcher creates a new FileWatcher instance. +// filePath should be a path to a file, not a directory. +func NewFileWatcher(filePath string) (FileWatcher, error) { + watcher, err := fsnotify.NewWatcher() + if err != nil { + return nil, err + } + + exist, err := utils.PathExists(filePath) + if err != nil { + return nil, err + } + if !exist { + return nil, errors.New("file [" + filePath + "] not exist") + } + + fw := &fileWatcher{ + filePath: filePath, + watcher: watcher, + done: make(chan struct{}), + callbacks: make(map[int64]func(data []byte), 0), + } + + return fw, nil +} + +// FilePath returns the file address that the current object is listening to +func (fw *fileWatcher) FilePath() string { return fw.filePath } + +// CallbackSize returns the number of callback functions. +func (fw *fileWatcher) CallbackSize() int { + fw.lock.RLock() + defer fw.lock.RUnlock() + return len(fw.callbacks) +} + +// RegisterCallback sets the callback function. +func (fw *fileWatcher) RegisterCallback(callback func(data []byte)) int64 { + fw.lock.Lock() + defer fw.lock.Unlock() + + if fw.callbacks == nil { + fw.callbacks = make(map[int64]func(data []byte), 0) + } + + klog.Debugf("[local] filewatcher to %v registered callback\n", fw.filePath) + + uniqueID := fw.counter.Add(1) + fw.callbacks[uniqueID] = callback + return uniqueID +} + +// DeregisterCallback remove callback function. +func (fw *fileWatcher) DeregisterCallback(uniqueID int64) { + fw.lock.Lock() + defer fw.lock.Unlock() + + if _, exists := fw.callbacks[uniqueID]; !exists { + klog.Warnf("[local] FileWatcher callback %s not registered", uniqueID) + return + } + delete(fw.callbacks, uniqueID) + klog.Infof("[local] filewatcher to %v deregistered callback id: %v\n", fw.filePath, uniqueID) +} + +// Start starts monitoring file changes. +// This method will add the file to be monitored to the watcher and start the monitoring process instanctly. +func (fw *fileWatcher) StartWatching() error { + fw.lock.Lock() + if err := fw.watcher.Add(fw.filePath); err != nil { + return err + } + fw.lock.Unlock() + + go func() { + defer func() { + if r := recover(); r != nil { + klog.Errorf("[local] file watcher panic: %v\n", r) + } + }() + fw.start() + }() + + return nil +} + +// StopWatching Stop stops monitoring file changes. +// Stop watching will close the done channel, and do not restart again. +func (fw *fileWatcher) StopWatching() { + fw.lock.Lock() + defer fw.lock.Unlock() + klog.Infof("[local] stop watching file: %s", fw.filePath) + close(fw.done) +} + +// start responsible for handling fsnotify event information. +func (fw *fileWatcher) start() { + defer fw.watcher.Close() + for { + select { + case event, ok := <-fw.watcher.Events: + if !ok { + return + } + if event.Has(fsnotify.Write) { + if err := fw.CallOnceAll(); err != nil { + klog.Errorf("[local] read config file failed: %v\n", err) + } + } + if event.Has(fsnotify.Remove) { + klog.Warnf("[local] file %s is removed, stop watching", fw.filePath) + fw.StopWatching() + } + case err, ok := <-fw.watcher.Errors: + if !ok { + return + } + klog.Errorf("[local] file watcher meet error: %v\n", err) + case <-fw.done: + return + } + } +} + +// CallOnceAll calls the callback function list once. +func (fw *fileWatcher) CallOnceAll() error { + data, err := os.ReadFile(fw.filePath) + if err != nil { + return err + } + + for key, callback := range fw.callbacks { + if callback == nil { + fw.DeregisterCallback(key) // When encountering Nil's callback function, directly cancel it here. + klog.Warnf("[local] filewatcher callback %v is nil, deregister it", key) + continue + } + callback(data) + } + return nil +} + +// CallOnceSpecific calls the callback function once by uniqueID. +func (fw *fileWatcher) CallOnceSpecific(uniqueID int64) error { + data, err := os.ReadFile(fw.filePath) + if err != nil { + return err + } + + if callback, ok := fw.callbacks[uniqueID]; ok { + callback(data) + } else { + return errors.New("not found callback for id: " + strconv.FormatInt(uniqueID, 10)) + } + return nil +} diff --git a/config/file/go.mod b/config/file/go.mod index f2c9782..0e11ee8 100644 --- a/config/file/go.mod +++ b/config/file/go.mod @@ -7,7 +7,6 @@ replace github.com/apache/thrift => github.com/apache/thrift v0.13.0 require ( github.com/bytedance/sonic v1.11.2 github.com/cloudwego/kitex v0.9.1 - github.com/cloudwego/kitex-examples v0.3.3 github.com/fsnotify/fsnotify v1.7.0 github.com/stretchr/testify v1.8.4 sigs.k8s.io/yaml v1.4.0 @@ -34,11 +33,9 @@ require ( github.com/jhump/protoreflect v1.8.2 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect - github.com/kr/text v0.2.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/gls v0.0.0-20220109145502-612d0167dce5 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/oleiade/lane v1.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/tidwall/gjson v1.14.4 // indirect @@ -52,7 +49,7 @@ require ( golang.org/x/text v0.13.0 // indirect google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect + google.golang.org/grpc v1.59.0 // indirect google.golang.org/protobuf v1.31.0 // indirect - gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/config/file/mock/filewatcher_mock.go b/config/file/mock/filewatcher_mock.go new file mode 100644 index 0000000..d5e3555 --- /dev/null +++ b/config/file/mock/filewatcher_mock.go @@ -0,0 +1,37 @@ +// Copyright 2024 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package mock + +import "github.com/cloudwego-contrib/cwgo-pkg/config/file/filewatcher" + +type fwmock struct{} + +// NewMockFileWatcher will return a mock filewatcher +func NewMockFileWatcher() filewatcher.FileWatcher { return &fwmock{} } + +func (fw *fwmock) FilePath() string { return "test" } + +func (fw *fwmock) CallbackSize() int { return 1 } + +func (fw *fwmock) RegisterCallback(callback func(data []byte)) int64 { return 0 } + +func (fw *fwmock) DeregisterCallback(uniqueID int64) {} + +func (fw *fwmock) StartWatching() error { return nil } + +func (fw *fwmock) StopWatching() {} + +func (fw *fwmock) CallOnceAll() error { return nil } + +func (fw *fwmock) CallOnceSpecific(uniqueID int64) error { return nil } diff --git a/config/file/monitor/monitor.go b/config/file/monitor/monitor.go new file mode 100644 index 0000000..d038ae4 --- /dev/null +++ b/config/file/monitor/monitor.go @@ -0,0 +1,195 @@ +// Copyright 2024 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package monitor + +import ( + "errors" + "sync" + "sync/atomic" + + "github.com/cloudwego-contrib/cwgo-pkg/config/file/filewatcher" + "github.com/cloudwego-contrib/cwgo-pkg/config/file/parser" + "github.com/cloudwego-contrib/cwgo-pkg/config/file/utils" + "github.com/cloudwego/kitex/pkg/klog" +) + +type ConfigMonitor interface { + Key() string + Config() interface{} + CallbackSize() int + Start() error + WatcherID() int64 + Stop() + SetManager(manager parser.ConfigManager) + SetParser(parser parser.ConfigParser) + SetParams(params *parser.ConfigParam) + ConfigParse(kind parser.ConfigType, data []byte, config interface{}) error + RegisterCallback(callback func()) int64 + DeregisterCallback(uniqueID int64) +} + +type configMonitor struct { + // support customise parser + parser parser.ConfigParser // Parser for the config file + params *parser.ConfigParam // params for the config file + manager parser.ConfigManager // Manager for the config file + config interface{} // config details + fileWatcher filewatcher.FileWatcher // local config file watcher + callbacks map[int64]func() // callbacks when config file changed + key string // key of the config in the config file + id int64 // unique id for filewatcher to register/deregister + lock sync.RWMutex // mutex + counter atomic.Int64 // unique id for callbacks, only increase +} + +// NewConfigMonitor init a monitor for the config file +func NewConfigMonitor(key string, watcher filewatcher.FileWatcher, opts ...utils.Option) (ConfigMonitor, error) { + if key == "" { + return nil, errors.New("empty config key") + } + if watcher == nil { + return nil, errors.New("filewatcher is nil") + } + + option := &utils.Options{ + Parser: parser.DefaultConfigParser(), + Params: parser.DefaultConfigParam(), + } + + for _, opt := range opts { + opt(option) + } + + return &configMonitor{ + fileWatcher: watcher, + key: key, + callbacks: make(map[int64]func(), 0), + parser: option.Parser, + params: option.Params, + }, nil +} + +// Key return the key of the config file +func (c *configMonitor) Key() string { return c.key } + +// Config return the config details +func (c *configMonitor) Config() interface{} { return c.config } + +// CallbackSize return the size of the callbacks +func (c *configMonitor) CallbackSize() int { + c.lock.RLock() + defer c.lock.RUnlock() + return len(c.callbacks) +} + +// WatcherID return the unique id of the filewatcher +func (c *configMonitor) WatcherID() int64 { return c.id } + +// Start starts the file watch progress +func (c *configMonitor) Start() error { + if c.manager == nil { + return errors.New("not set manager for config file") + } + + c.id = c.fileWatcher.RegisterCallback(c.parseHandler) + + return c.fileWatcher.CallOnceSpecific(c.id) +} + +// Stop stops the file watch progress +func (c *configMonitor) Stop() { + for k := range c.callbacks { + c.DeregisterCallback(k) + } + + // deregister current object's parseHandler from filewatcher + c.fileWatcher.DeregisterCallback(c.id) +} + +// SetManager set the manager for the config file +func (c *configMonitor) SetManager(manager parser.ConfigManager) { c.manager = manager } + +// SetParser set the parser for the config file +func (c *configMonitor) SetParser(parser parser.ConfigParser) { + c.parser = parser +} + +// SetParams set the params for the config file, such as file type +func (c *configMonitor) SetParams(params *parser.ConfigParam) { + c.params = params +} + +// ConfigParse call configMonitor.parser.Decode() +func (c *configMonitor) ConfigParse(kind parser.ConfigType, data []byte, config interface{}) error { + return c.parser.Decode(kind, data, config) +} + +// RegisterCallback add callback function, it will be called when file changed, return key for deregister +func (c *configMonitor) RegisterCallback(callback func()) int64 { + c.lock.Lock() + defer c.lock.Unlock() + + if c.callbacks == nil { + c.callbacks = make(map[int64]func()) + } + + key := c.counter.Add(1) + c.callbacks[key] = callback + + klog.Debugf("[local] config monitor registered callback, id: %v\n", key) + return key +} + +// DeregisterCallback remove callback function. +func (c *configMonitor) DeregisterCallback(key int64) { + c.lock.Lock() + defer c.lock.Unlock() + + if _, exists := c.callbacks[key]; !exists { + klog.Warnf("[local] ConfigMonitor callback %s not registered", key) + return + } + delete(c.callbacks, key) +} + +// parseHandler parse and invoke each function in the callbacks array +func (c *configMonitor) parseHandler(data []byte) { + resp := c.manager + + kind := c.params + err := c.parser.Decode(kind.Type, data, resp) + if err != nil { + klog.Errorf("[local] failed to parse the config file: %v\n", err) + return + } + + c.config = resp.GetConfig(c.key) + if c.config == nil { + klog.Warnf("[local] not matching key found, skip. current key: %v\n", c.key) + return + } + + if len(c.callbacks) > 0 { + for key, callback := range c.callbacks { + if callback == nil { + c.DeregisterCallback(key) // When encountering Nil's callback function, directly cancel it here. + klog.Warnf("[local] filewatcher callback %v is nil, deregister it", key) + continue + } + callback() + } + } + klog.Infof("[local] config parse and update complete \n") +} diff --git a/config/file/monitor/monitor_test.go b/config/file/monitor/monitor_test.go new file mode 100644 index 0000000..2850c32 --- /dev/null +++ b/config/file/monitor/monitor_test.go @@ -0,0 +1,227 @@ +// Copyright 2024 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package monitor + +import ( + "testing" + + "github.com/cloudwego-contrib/cwgo-pkg/config/file/filewatcher" + "github.com/cloudwego-contrib/cwgo-pkg/config/file/mock" + "github.com/cloudwego-contrib/cwgo-pkg/config/file/parser" +) + +const ( + filepath = "./../testdata/test.json" +) + +func TestNewConfigMonitor(t *testing.T) { + m := mock.NewMockFileWatcher() + if _, err := NewConfigMonitor("test", m); err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } +} + +func TestNewConfigMonitorFailed(t *testing.T) { + m := mock.NewMockFileWatcher() + if _, err := NewConfigMonitor("", m); err == nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + if _, err := NewConfigMonitor("test", nil); err == nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } +} + +func TestKey(t *testing.T) { + m := mock.NewMockFileWatcher() + cm, err := NewConfigMonitor("test", m) + if err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + if cm.Key() != "test" { + t.Errorf("Key() error") + } +} + +func TestSetManager(t *testing.T) { + m := mock.NewMockFileWatcher() + cm, err := NewConfigMonitor("test", m) + if err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + cm.SetManager(&parser.ServerFileManager{}) +} + +func TestSetParser(t *testing.T) { + m := mock.NewMockFileWatcher() + cm, err := NewConfigMonitor("test", m) + if err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + cm.SetParser(&parser.Parser{}) + + // use json format test ConfigParse + kind := parser.JSON + jsonData := []byte(`{"key": "value"}`) + var config struct{} + err = cm.ConfigParse(kind, jsonData, &config) + if err != nil { + t.Errorf("ConfigParse() error = %v", err) + } +} + +func TestSetParams(t *testing.T) { + m := mock.NewMockFileWatcher() + cm, err := NewConfigMonitor("test", m) + if err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + + cm.SetParams(&parser.ConfigParam{}) +} + +func TestRegisterCallback(t *testing.T) { + m := mock.NewMockFileWatcher() + cm, err := NewConfigMonitor("test", m) + if err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + cm.RegisterCallback(nil) +} + +func TestDeregisterCallback(t *testing.T) { + m := mock.NewMockFileWatcher() + cm, err := NewConfigMonitor("test", m) + if err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + cm.DeregisterCallback(1) +} + +func TestStartFailed(t *testing.T) { + m := mock.NewMockFileWatcher() + cm, err := NewConfigMonitor("test", m) + if err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + if err := cm.Start(); err == nil { + t.Errorf("filewatcher not sert manager, Start() should error, but not") + } +} + +func TestStartSuccess(t *testing.T) { + m := mock.NewMockFileWatcher() + cm, err := NewConfigMonitor("test", m) + if err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + cm.SetManager(&parser.ServerFileManager{}) + if err := cm.Start(); err != nil { + t.Errorf("Start() error = %v", err) + } +} + +func TestStop(t *testing.T) { + m := mock.NewMockFileWatcher() + cm, err := NewConfigMonitor("test", m) + if err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + cm.Stop() +} + +func TestEntireProgressWithSingleKey(t *testing.T) { + testProcess(filepath, []string{"Test1"}, t) +} + +func TestEntireProgressWithDifferentKey(t *testing.T) { + testProcess(filepath, []string{"Test1", "Test2"}, t) +} + +func TestEntireProcessWithSameKey(t *testing.T) { + testProcess(filepath, []string{"Test1", "Test1"}, t) +} + +func createConfigManager(fw filewatcher.FileWatcher, key string, t *testing.T) ConfigMonitor { + // create a config monitor object + cm, err := NewConfigMonitor(key, fw) + if err != nil { + t.Errorf("NewConfigMonitor() error = %v", err) + } + // set manager + cm.SetManager(&parser.ServerFileManager{}) + + // register callback + id := cm.RegisterCallback(func() { + t.Errorf("THIS CALLBACK SHOULD NOT BE INVOKED") + }) + + cm.RegisterCallback(func() { + t.Logf("INVOKE CALLBACK ON CONFIG MANAGER, index: %v\n", cm.WatcherID()) + }) + cm.DeregisterCallback(id) + + // start monitoring + if err = cm.Start(); err != nil { + t.Errorf("Start() error = %v", err) + } + + // call specific callback + t.Log("call specific ConfigManager0") + fw.CallOnceSpecific(id) + + return cm +} + +func testProcess(filepath string, mapKey []string, t *testing.T) { + if len(mapKey) < 1 { + t.Errorf("mapKey is empty") + } + + // create a file watcher object + fw, err := filewatcher.NewFileWatcher(filepath) + if err != nil { + t.Errorf("NewFileWatcher() error = %v", err) + } + // start watching file changes + if err = fw.StartWatching(); err != nil { + t.Errorf("StartWatching() error = %v", err) + } + + cm := createConfigManager(fw, mapKey[0], t) + + // not have enough key + if len(mapKey) < 2 { + t.Log("Without enough map keys, do not execute multi-key listening test.") + cm.Stop() + fw.StopWatching() + return + } + + // CREATE ANOTHER NEW CONFIG MONITOR + cm1 := createConfigManager(fw, mapKey[1], t) + + t.Log("call all ConfigManager") + fw.CallOnceAll() + + t.Log("DeregisterCallback ConfigManager0 and CallOnceAll") + cm.Stop() + fw.CallOnceAll() + + t.Log("DeregisterCallback ConfigManager1 and CallOnceAll") + cm1.Stop() + fw.CallOnceAll() + + fw.StopWatching() +} diff --git a/config/file/utils/set.go b/config/file/utils/set.go deleted file mode 100644 index 7b7cb3c..0000000 --- a/config/file/utils/set.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2024 CloudWeGo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils - -import "sync" - -// ThreadSafeSet wrapper of Set. -type ThreadSafeSet struct { - sync.RWMutex - s Set -} - -// DiffAndEmplace returns the keys that are not in other and emplace the old set. -func (ts *ThreadSafeSet) DiffAndEmplace(other Set) []string { - ts.Lock() - defer ts.Unlock() - out := ts.s.Diff(other) - ts.s = other - return out -} - -// Set map template. -type Set map[string]bool - -// Diff returns the keys that are not in other -func (s Set) Diff(other Set) []string { - out := make([]string, 0, len(s)) - for key := range s { - if _, ok := other[key]; !ok { - out = append(out, key) - } - } - return out -} diff --git a/config/file/utils/set_test.go b/config/file/utils/set_test.go index 94ec404..72ec6c7 100644 --- a/config/file/utils/set_test.go +++ b/config/file/utils/set_test.go @@ -15,6 +15,7 @@ package utils import ( + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "sort" "testing" @@ -22,21 +23,21 @@ import ( ) func TestSet(t *testing.T) { - ts := &ThreadSafeSet{} - m1 := Set{ + ts := &cwutils.ThreadSafeSet{} + m1 := cwutils.Set{ "h1": true, "h2": true, } got := ts.DiffAndEmplace(m1) assert.Equal(t, []string([]string{}), got) - assert.Equal(t, m1, ts.s) + assert.Equal(t, m1, ts.GetSet()) - m2 := Set{ + m2 := cwutils.Set{ "h3": true, "h4": true, } got = ts.DiffAndEmplace(m2) sort.Strings(got) assert.Equal(t, []string([]string{"h1", "h2"}), got) - assert.Equal(t, m2, ts.s) + assert.Equal(t, m2, ts.GetSet()) } diff --git a/config/nacos/client/circuit_breaker.go b/config/nacos/client/circuit_breaker.go index 37841eb..142d34c 100644 --- a/config/nacos/client/circuit_breaker.go +++ b/config/nacos/client/circuit_breaker.go @@ -15,6 +15,7 @@ package client import ( + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "strings" "github.com/cloudwego-contrib/cwgo-pkg/config/nacos/nacos" @@ -82,10 +83,10 @@ func initCircuitBreaker(param vo.ConfigParam, dest, src string, nacosClient nacos.Client, uniqueID int64, ) *circuitbreak.CBSuite { cb := circuitbreak.NewCBSuite(genServiceCBKeyWithRPCInfo) - lcb := utils.ThreadSafeSet{} + lcb := cwutils.ThreadSafeSet{} onChangeCallback := func(data string, parser nacos.ConfigParser) { - set := utils.Set{} + set := cwutils.Set{} configs := map[string]circuitbreak.CBConfig{} err := parser.Decode(param.Type, data, &configs) if err != nil { diff --git a/config/nacos/client/retry.go b/config/nacos/client/retry.go index af69109..5b405a9 100644 --- a/config/nacos/client/retry.go +++ b/config/nacos/client/retry.go @@ -15,6 +15,7 @@ package client import ( + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego/kitex/client" "github.com/cloudwego/kitex/pkg/klog" "github.com/cloudwego/kitex/pkg/retry" @@ -60,7 +61,7 @@ func initRetryContainer(param vo.ConfigParam, dest string, ) *retry.Container { retryContainer := retry.NewRetryContainerWithPercentageLimit() - ts := utils.ThreadSafeSet{} + ts := cwutils.ThreadSafeSet{} onChangeCallback := func(data string, parser nacos.ConfigParser) { // the key is method name, wildcard "*" can match anything. @@ -71,7 +72,7 @@ func initRetryContainer(param vo.ConfigParam, dest string, return } - set := utils.Set{} + set := cwutils.Set{} for method, policy := range rcs { set[method] = true if policy.BackupPolicy != nil && policy.FailurePolicy != nil { diff --git a/config/nacos/go.mod b/config/nacos/go.mod index 915847f..45c8c05 100644 --- a/config/nacos/go.mod +++ b/config/nacos/go.mod @@ -2,7 +2,6 @@ module github.com/cloudwego-contrib/cwgo-pkg/config/nacos go 1.21 - require ( github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b github.com/cloudwego/kitex v0.7.3 @@ -36,7 +35,7 @@ require ( github.com/google/pprof v0.0.0-20230509042627-b1315fad0c5a // indirect github.com/iancoleman/strcase v0.2.0 // indirect github.com/jhump/protoreflect v1.8.2 // indirect - github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect + github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/config/nacos/utils/set.go b/config/nacos/utils/set.go deleted file mode 100644 index 7b7cb3c..0000000 --- a/config/nacos/utils/set.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2024 CloudWeGo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils - -import "sync" - -// ThreadSafeSet wrapper of Set. -type ThreadSafeSet struct { - sync.RWMutex - s Set -} - -// DiffAndEmplace returns the keys that are not in other and emplace the old set. -func (ts *ThreadSafeSet) DiffAndEmplace(other Set) []string { - ts.Lock() - defer ts.Unlock() - out := ts.s.Diff(other) - ts.s = other - return out -} - -// Set map template. -type Set map[string]bool - -// Diff returns the keys that are not in other -func (s Set) Diff(other Set) []string { - out := make([]string, 0, len(s)) - for key := range s { - if _, ok := other[key]; !ok { - out = append(out, key) - } - } - return out -} diff --git a/config/nacos/v2/client/circuit_breaker.go b/config/nacos/v2/client/circuit_breaker.go index 24c164f..b2f9a1b 100644 --- a/config/nacos/v2/client/circuit_breaker.go +++ b/config/nacos/v2/client/circuit_breaker.go @@ -15,6 +15,7 @@ package client import ( + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "strings" "github.com/cloudwego-contrib/cwgo-pkg/config/nacos/v2/nacos" @@ -82,10 +83,10 @@ func initCircuitBreaker(param vo.ConfigParam, dest, src string, nacosClient nacos.Client, uniqueID int64, ) *circuitbreak.CBSuite { cb := circuitbreak.NewCBSuite(genServiceCBKeyWithRPCInfo) - lcb := utils.ThreadSafeSet{} + lcb := cwutils.ThreadSafeSet{} onChangeCallback := func(data string, parser nacos.ConfigParser) { - set := utils.Set{} + set := cwutils.Set{} configs := map[string]circuitbreak.CBConfig{} err := parser.Decode(param.Type, data, &configs) if err != nil { diff --git a/config/nacos/v2/client/retry.go b/config/nacos/v2/client/retry.go index b31b6ec..9b38a8d 100644 --- a/config/nacos/v2/client/retry.go +++ b/config/nacos/v2/client/retry.go @@ -16,6 +16,7 @@ package client import ( "github.com/cloudwego-contrib/cwgo-pkg/config/nacos/v2/nacos" "github.com/cloudwego-contrib/cwgo-pkg/config/nacos/v2/utils" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego/kitex/client" "github.com/cloudwego/kitex/pkg/klog" "github.com/cloudwego/kitex/pkg/retry" @@ -58,7 +59,7 @@ func initRetryContainer(param vo.ConfigParam, dest string, ) *retry.Container { retryContainer := retry.NewRetryContainerWithPercentageLimit() - ts := utils.ThreadSafeSet{} + ts := cwutils.ThreadSafeSet{} onChangeCallback := func(data string, parser nacos.ConfigParser) { // the key is method name, wildcard "*" can match anything. @@ -69,7 +70,7 @@ func initRetryContainer(param vo.ConfigParam, dest string, return } - set := utils.Set{} + set := cwutils.Set{} for method, policy := range rcs { set[method] = true if policy.BackupPolicy != nil && policy.FailurePolicy != nil { diff --git a/config/nacos/v2/go.mod b/config/nacos/v2/go.mod index c92579f..38ae284 100644 --- a/config/nacos/v2/go.mod +++ b/config/nacos/v2/go.mod @@ -2,7 +2,7 @@ module github.com/cloudwego-contrib/cwgo-pkg/config/nacos/v2 go 1.21 -toolchain go1.21.11 + require ( github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b @@ -44,7 +44,6 @@ require ( github.com/google/pprof v0.0.0-20230509042627-b1315fad0c5a // indirect github.com/iancoleman/strcase v0.2.0 // indirect github.com/jhump/protoreflect v1.8.2 // indirect - github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect @@ -64,7 +63,6 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.26.0 // indirect golang.org/x/arch v0.2.0 // indirect - golang.org/x/crypto v0.17.0 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.15.0 // indirect diff --git a/config/nacos/v2/utils/set.go b/config/nacos/v2/utils/set.go deleted file mode 100644 index 7b7cb3c..0000000 --- a/config/nacos/v2/utils/set.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2024 CloudWeGo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils - -import "sync" - -// ThreadSafeSet wrapper of Set. -type ThreadSafeSet struct { - sync.RWMutex - s Set -} - -// DiffAndEmplace returns the keys that are not in other and emplace the old set. -func (ts *ThreadSafeSet) DiffAndEmplace(other Set) []string { - ts.Lock() - defer ts.Unlock() - out := ts.s.Diff(other) - ts.s = other - return out -} - -// Set map template. -type Set map[string]bool - -// Diff returns the keys that are not in other -func (s Set) Diff(other Set) []string { - out := make([]string, 0, len(s)) - for key := range s { - if _, ok := other[key]; !ok { - out = append(out, key) - } - } - return out -} diff --git a/config/nacos/v2/utils/set_test.go b/config/nacos/v2/utils/set_test.go deleted file mode 100644 index 94ec404..0000000 --- a/config/nacos/v2/utils/set_test.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2024 CloudWeGo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils - -import ( - "sort" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestSet(t *testing.T) { - ts := &ThreadSafeSet{} - m1 := Set{ - "h1": true, - "h2": true, - } - got := ts.DiffAndEmplace(m1) - assert.Equal(t, []string([]string{}), got) - assert.Equal(t, m1, ts.s) - - m2 := Set{ - "h3": true, - "h4": true, - } - got = ts.DiffAndEmplace(m2) - sort.Strings(got) - assert.Equal(t, []string([]string{"h1", "h2"}), got) - assert.Equal(t, m2, ts.s) -} diff --git a/config/utils/go.mod b/config/utils/go.mod new file mode 100644 index 0000000..9eaad44 --- /dev/null +++ b/config/utils/go.mod @@ -0,0 +1,21 @@ +module github.com/cloudwego-contrib/cwgo-pkg/config/utils + +go 1.21.13 + +require ( + github.com/bytedance/sonic v1.12.2 + github.com/stretchr/testify v1.8.1 + sigs.k8s.io/yaml v1.4.0 +) + +require ( + github.com/bytedance/sonic/loader v0.2.0 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/klauspost/cpuid/v2 v2.0.9 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/config/utils/parser.go b/config/utils/parser.go new file mode 100644 index 0000000..6ef4a93 --- /dev/null +++ b/config/utils/parser.go @@ -0,0 +1,69 @@ +/* + * Copyright 2024 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package utils + +import ( + "fmt" + "github.com/bytedance/sonic" + "sigs.k8s.io/yaml" +) + +const ( + JSON ConfigType = "json" + YAML ConfigType = "yaml" + HCL ConfigType = "hcl" +) + +var _ ConfigParser = &parser{} + +// ConfigParser the parser for Apollo config. +type ConfigParser interface { + Decode(kind ConfigType, data string, config interface{}) error +} + +type parser struct{} + +// Decode decodes the data to struct in specified format. +func (p *parser) Decode(kind ConfigType, data string, config interface{}) error { + switch kind { + case JSON: + return sonic.Unmarshal([]byte(data), config) + case YAML: + return yaml.Unmarshal([]byte(data), config) + default: + return fmt.Errorf("unsupported config data type %s", kind) + } +} + +// DefaultConfigParse default apollo config parser. +func DefaultConfigParse() ConfigParser { + return &parser{} +} + +// CustomFunction use for customize the config parameters. +type ( + ConfigType string + ConfigContent string +) + +// ConfigParamConfig use for render the dataId or group info by go template, ref: https://pkg.go.dev/text/template +// The fixed key shows as below. +type ConfigParamConfig struct { + Category string + ClientServiceName string + ServerServiceName string +} diff --git a/config/apollo/utils/set.go b/config/utils/set.go similarity index 51% rename from config/apollo/utils/set.go rename to config/utils/set.go index 597f225..480940c 100644 --- a/config/apollo/utils/set.go +++ b/config/utils/set.go @@ -1,16 +1,18 @@ -// Copyright 2023 CloudWeGo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * Copyright 2024 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package utils @@ -22,6 +24,10 @@ type ThreadSafeSet struct { s Set } +func (ts *ThreadSafeSet) GetSet() Set { + return ts.s +} + // DiffAndEmplace returns the keys that are not in other and emplace the old set. func (ts *ThreadSafeSet) DiffAndEmplace(other Set) []string { ts.Lock() diff --git a/config/nacos/utils/set_test.go b/config/utils/set_test.go similarity index 100% rename from config/nacos/utils/set_test.go rename to config/utils/set_test.go diff --git a/config/zookeeper/client/circuit_breaker.go b/config/zookeeper/client/circuit_breaker.go index b759c41..fcdd510 100644 --- a/config/zookeeper/client/circuit_breaker.go +++ b/config/zookeeper/client/circuit_breaker.go @@ -16,6 +16,7 @@ package client import ( "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "strings" "github.com/cloudwego-contrib/cwgo-pkg/config/zookeeper/utils" @@ -28,7 +29,7 @@ import ( // WithCircuitBreaker sets the circuit breaker policy from zookeeper configuration center. func WithCircuitBreaker(dest, src string, zookeeperClient zookeeper.Client, opts utils.Options) []client.Option { - param, err := zookeeperClient.ClientConfigParam(&zookeeper.ConfigParamConfig{ + param, err := zookeeperClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: circuitBreakerConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -81,14 +82,14 @@ func genServiceCBKey(toService, method string) string { func initCircuitBreaker(path string, uniqueID int64, dest string, zookeeperClient zookeeper.Client) *circuitbreak.CBSuite { cb := circuitbreak.NewCBSuite(genServiceCBKeyWithRPCInfo) - lcb := utils.ThreadSafeSet{} + lcb := cwutils.ThreadSafeSet{} - onChangeCallback := func(restoreDefault bool, data string, parser zookeeper.ConfigParser) { - set := utils.Set{} + onChangeCallback := func(restoreDefault bool, data string, parser cwutils.ConfigParser) { + set := cwutils.Set{} configs := map[string]circuitbreak.CBConfig{} if !restoreDefault { - err := parser.Decode(data, &configs) + err := parser.Decode(cwutils.JSON, data, &configs) if err != nil { klog.Warnf("[zookeeper] %s client zookeeper circuit breaker: unmarshal data %s failed: %s, skip...", path, data, err) return diff --git a/config/zookeeper/client/degradation.go b/config/zookeeper/client/degradation.go index ea5132c..361ced9 100644 --- a/config/zookeeper/client/degradation.go +++ b/config/zookeeper/client/degradation.go @@ -16,6 +16,7 @@ package client import ( "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego-contrib/cwgo-pkg/config/zookeeper/pkg/degradation" "github.com/cloudwego-contrib/cwgo-pkg/config/zookeeper/utils" @@ -25,7 +26,7 @@ import ( ) func WithDegradation(dest, src string, zookeeperClient zookeeper.Client, opts utils.Options) []client.Option { - param, err := zookeeperClient.ClientConfigParam(&zookeeper.ConfigParamConfig{ + param, err := zookeeperClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: degradationConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -53,10 +54,10 @@ func WithDegradation(dest, src string, zookeeperClient zookeeper.Client, opts ut func initDegradation(path string, uniqueID int64, dest string, zookeeperClient zookeeper.Client) *degradation.Container { container := degradation.NewContainer() - onChangeCallback := func(restoreDefault bool, data string, parser zookeeper.ConfigParser) { + onChangeCallback := func(restoreDefault bool, data string, parser cwutils.ConfigParser) { config := °radation.Config{} if !restoreDefault { - err := parser.Decode(data, config) + err := parser.Decode(cwutils.JSON, data, config) if err != nil { klog.Warnf("[zookeeper] %s server zookeeper degradation config: unmarshal data %s failed: %s, skip...", path, data, err) return diff --git a/config/zookeeper/client/retry.go b/config/zookeeper/client/retry.go index f48ec31..4554a40 100644 --- a/config/zookeeper/client/retry.go +++ b/config/zookeeper/client/retry.go @@ -16,6 +16,7 @@ package client import ( "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego-contrib/cwgo-pkg/config/zookeeper/utils" "github.com/cloudwego-contrib/cwgo-pkg/config/zookeeper/zookeeper" @@ -26,7 +27,7 @@ import ( // WithRetryPolicy sets the retry policy from zookeeper configuration center. func WithRetryPolicy(dest, src string, zookeeperClient zookeeper.Client, opts utils.Options) []client.Option { - param, err := zookeeperClient.ClientConfigParam(&zookeeper.ConfigParamConfig{ + param, err := zookeeperClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: retryConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -55,20 +56,20 @@ func WithRetryPolicy(dest, src string, zookeeperClient zookeeper.Client, opts ut func initRetryContainer(path string, uniqueID int64, dest string, zookeeperClient zookeeper.Client) *retry.Container { retryContainer := retry.NewRetryContainerWithPercentageLimit() - ts := utils.ThreadSafeSet{} + ts := cwutils.ThreadSafeSet{} - onChangeCallback := func(restoreDefault bool, data string, parser zookeeper.ConfigParser) { + onChangeCallback := func(restoreDefault bool, data string, parser cwutils.ConfigParser) { // the key is method name, wildcard "*" can match anything. rcs := map[string]*retry.Policy{} if !restoreDefault && data != "" { - err := parser.Decode(data, &rcs) + err := parser.Decode(cwutils.JSON, data, &rcs) if err != nil { klog.Warnf("[zookeeper] %s client zookeeper retry: unmarshal data %s failed: %s, skip...", path, data, err) return } } - set := utils.Set{} + set := cwutils.Set{} for method, policy := range rcs { set[method] = true if policy.BackupPolicy != nil && policy.FailurePolicy != nil { diff --git a/config/zookeeper/client/rpc_timeout.go b/config/zookeeper/client/rpc_timeout.go index 4626718..92b6ed1 100644 --- a/config/zookeeper/client/rpc_timeout.go +++ b/config/zookeeper/client/rpc_timeout.go @@ -16,6 +16,7 @@ package client import ( "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "github.com/cloudwego-contrib/cwgo-pkg/config/zookeeper/utils" "github.com/cloudwego-contrib/cwgo-pkg/config/zookeeper/zookeeper" @@ -27,7 +28,7 @@ import ( // WithRPCTimeout sets the RPC timeout policy from zookeeper configuration center. func WithRPCTimeout(dest, src string, zookeeperClient zookeeper.Client, opts utils.Options) []client.Option { - param, err := zookeeperClient.ClientConfigParam(&zookeeper.ConfigParamConfig{ + param, err := zookeeperClient.ClientConfigParam(&cwutils.ConfigParamConfig{ Category: rpcTimeoutConfigName, ServerServiceName: dest, ClientServiceName: src, @@ -56,10 +57,10 @@ func WithRPCTimeout(dest, src string, zookeeperClient zookeeper.Client, opts uti func initRPCTimeoutContainer(path string, uniqueID int64, dest string, zookeeperClient zookeeper.Client) rpcinfo.TimeoutProvider { rpcTimeoutContainer := rpctimeout.NewContainer() - onChangeCallback := func(restoreDefault bool, data string, parser zookeeper.ConfigParser) { + onChangeCallback := func(restoreDefault bool, data string, parser cwutils.ConfigParser) { configs := map[string]*rpctimeout.RPCTimeout{} if !restoreDefault { - err := parser.Decode(data, &configs) + err := parser.Decode(cwutils.JSON, data, &configs) if err != nil { klog.Warnf("[zookeeper] %s client zookeeper rpc timeout: unmarshal data %s failed: %s, skip...", path, data, err) return diff --git a/config/zookeeper/go.mod b/config/zookeeper/go.mod index 0961cdc..21318ef 100644 --- a/config/zookeeper/go.mod +++ b/config/zookeeper/go.mod @@ -2,7 +2,6 @@ module github.com/cloudwego-contrib/cwgo-pkg/config/zookeeper go 1.21 - require ( github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b github.com/cloudwego/configmanager v0.2.0 diff --git a/config/zookeeper/server/limiter.go b/config/zookeeper/server/limiter.go index 03d910b..15f962f 100644 --- a/config/zookeeper/server/limiter.go +++ b/config/zookeeper/server/limiter.go @@ -16,6 +16,7 @@ package server import ( "context" + cwutils "github.com/cloudwego-contrib/cwgo-pkg/config/utils" "sync/atomic" "github.com/cloudwego-contrib/cwgo-pkg/config/zookeeper/utils" @@ -28,7 +29,7 @@ import ( // WithLimiter sets the limiter config from zookeeper configuration center. func WithLimiter(dest string, zookeeperClient zookeeper.Client, opts utils.Options) server.Option { - param, err := zookeeperClient.ServerConfigParam(&zookeeper.ConfigParamConfig{ + param, err := zookeeperClient.ServerConfigParam(&cwutils.ConfigParamConfig{ Category: limiterConfigName, ServerServiceName: dest, }) @@ -55,10 +56,10 @@ func initLimitOptions(path string, uniqueID int64, dest string, zookeeperClient u.UpdateLimit(opt) updater.Store(u) } - onChangeCallback := func(restoreDefault bool, data string, parser zookeeper.ConfigParser) { + onChangeCallback := func(restoreDefault bool, data string, parser cwutils.ConfigParser) { lc := &limiter.LimiterConfig{} if !restoreDefault && data != "" { - err := parser.Decode(data, lc) + err := parser.Decode(cwutils.JSON, data, lc) if err != nil { klog.Warnf("[zookeeper] %s server zookeeper config: unmarshal data %s failed: %s, skip...", dest, data, err) return diff --git a/config/zookeeper/utils/set.go b/config/zookeeper/utils/set.go deleted file mode 100644 index 597f225..0000000 --- a/config/zookeeper/utils/set.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2023 CloudWeGo Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package utils - -import "sync" - -// ThreadSafeSet wrapper of Set. -type ThreadSafeSet struct { - sync.RWMutex - s Set -} - -// DiffAndEmplace returns the keys that are not in other and emplace the old set. -func (ts *ThreadSafeSet) DiffAndEmplace(other Set) []string { - ts.Lock() - defer ts.Unlock() - out := ts.s.Diff(other) - ts.s = other - return out -} - -// Set map template. -type Set map[string]bool - -// Diff returns the keys that are not in other -func (s Set) Diff(other Set) []string { - out := make([]string, 0, len(s)) - for key := range s { - if _, ok := other[key]; !ok { - out = append(out, key) - } - } - return out -} diff --git a/config/zookeeper/zookeeper/parser.go b/config/zookeeper/zookeeper/parser.go index 9b6781b..380fb49 100644 --- a/config/zookeeper/zookeeper/parser.go +++ b/config/zookeeper/zookeeper/parser.go @@ -14,8 +14,6 @@ package zookeeper -import "encoding/json" - const ( //`{{$Prefix}}/{{$ClientName}}/{{$ServerName}}/{{$ConfigCategory}}` ZookeeperDefaultServer = "127.0.0.1:2181" ZookeeperDefaultClientPath = "{{.ClientServiceName}}/{{.ServerServiceName}}/{{.Category}}" @@ -25,27 +23,3 @@ const ( //`{{$Prefix}}/{{$ClientName}}/{{$ServerName}}/{{$ConfigCategory}}` // CustomFunction use for customize the config parameters. type CustomFunction func(*ConfigParam) - -// ConfigParamConfig use for render the path info by go template, ref: https://pkg.go.dev/text/template -// The fixed key shows as below. -type ConfigParamConfig struct { - Category string - ClientServiceName string - ServerServiceName string -} - -// ConfigParser the parser for zookeeper config. -type ConfigParser interface { - Decode(data string, config interface{}) error -} -type parser struct{} - -// Decode decodes the data to struct in specified format. -func (p *parser) Decode(data string, config interface{}) error { - return json.Unmarshal([]byte(data), config) -} - -// DefaultConfigParser default zookeeper config parser. -func defaultConfigParser() ConfigParser { - return &parser{} -} diff --git a/registry/consul/consulkitex/consul_registry.go b/registry/consul/consulkitex/consul_registry.go index 74755c8..f7f63d3 100644 --- a/registry/consul/consulkitex/consul_registry.go +++ b/registry/consul/consulkitex/consul_registry.go @@ -25,20 +25,14 @@ import ( "github.com/hashicorp/consul/api" ) -type options struct { - check *api.AgentServiceCheck -} - type consulRegistry struct { consulClient *api.Client opts options } -const kvJoinChar = ":" - -var _ registry.Registry = (*consulRegistry)(nil) - -var errIllegalTagChar = errors.New("illegal tag character") +type options struct { + check *api.AgentServiceCheck +} // Option is consul option. type Option func(o *options) @@ -48,6 +42,12 @@ func WithCheck(check *api.AgentServiceCheck) Option { return func(o *options) { o.check = check } } +const kvJoinChar = ":" + +var _ registry.Registry = (*consulRegistry)(nil) + +var errIllegalTagChar = errors.New("illegal tag character") + // NewConsulRegister create a new registry using consul. func NewConsulRegister(address string, opts ...Option) (registry.Registry, error) { config := api.DefaultConfig() diff --git a/registry/consul/options/option.go b/registry/consul/options/option.go new file mode 100644 index 0000000..e4cffa9 --- /dev/null +++ b/registry/consul/options/option.go @@ -0,0 +1,31 @@ +/* + * Copyright 2024 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package options + +import "github.com/hashicorp/consul/api" + +type options struct { + check *api.AgentServiceCheck +} + +// Option is the option of Consul. +type Option func(o *options) + +// WithCheck is consul registry-etcdhertz option to set AgentServiceCheck. +func WithCheck(check *api.AgentServiceCheck) Option { + return func(o *options) { o.check = check } +} diff --git a/registry/etcd/etcdhertz/Makefile b/registry/etcd/etcdhertz/Makefile index 5cc786b..81f5d89 100644 --- a/registry/etcd/etcdhertz/Makefile +++ b/registry/etcd/etcdhertz/Makefile @@ -3,8 +3,7 @@ REGISTRY=bitnami/etcd ETCD_VERSION=latest # run cluster prepare-cluster: - cd example - docker-compose up -d + cd example && docker-compose up -d # run single node in docker prepare: diff --git a/registry/etcd/etcdhertz/etcd_test.go b/registry/etcd/etcdhertz/etcd_test.go index 432e0d1..c81d876 100644 --- a/registry/etcd/etcdhertz/etcd_test.go +++ b/registry/etcd/etcdhertz/etcd_test.go @@ -249,7 +249,7 @@ func TestEtcdRegistryWithHertz(t *testing.T) { // register newClient, _ := client.NewClient() - resolver, _ := NewEtcdResolver([]string{"127.0.0.1:2379"}) + resolver, _ := NewEtcdResolver([]string{"127.0.0.1:20000"}) newClient.Use(sd.Discovery(resolver)) addr := fmt.Sprintf("http://" + srvName + "/ping") diff --git a/registry/etcd/etcdkitex/etcd_registry.go b/registry/etcd/etcdkitex/etcd_registry.go index 54004ce..c188c0f 100644 --- a/registry/etcd/etcdkitex/etcd_registry.go +++ b/registry/etcd/etcdkitex/etcd_registry.go @@ -107,6 +107,7 @@ func NewEtcdRegistryWithRetry(endpoints []string, retryConfig *retry.Config, opt return nil, err } return &etcdRegistry{ + prefix: cfg.Prefix, etcdClient: etcdClient, leaseTTL: getTTL(), retryConfig: retryConfig, diff --git a/registry/eureka/eurekakitex/entity/entity.go b/registry/eureka/eurekakitex/entity/entity.go deleted file mode 100644 index 639402c..0000000 --- a/registry/eureka/eurekakitex/entity/entity.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2021 CloudWeGo authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package entity - -type RegistryEntity struct { - Weight int - Tags map[string]string -} diff --git a/registry/polaris/go.sum b/registry/polaris/go.sum index 69772ec..562742a 100644 --- a/registry/polaris/go.sum +++ b/registry/polaris/go.sum @@ -36,8 +36,6 @@ git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3p github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY= @@ -62,12 +60,7 @@ github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/bytedance/go-tagexpr/v2 v2.9.2 h1:QySJaAIQgOEDQBLS3x9BxOWrnhqu5sQ+f6HaZIxD39I= github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM= -github.com/bytedance/gopkg v0.0.0-20210705062217-74c74ebadcae/go.mod h1:birsdqRCbwnckJbdAvcSao+AzOyibVEoWB55MjpYpB8= -github.com/bytedance/gopkg v0.0.0-20210709064845-3c00f9323f09/go.mod h1:birsdqRCbwnckJbdAvcSao+AzOyibVEoWB55MjpYpB8= -github.com/bytedance/gopkg v0.0.0-20210716082555-acbf5a2aa7e2/go.mod h1:birsdqRCbwnckJbdAvcSao+AzOyibVEoWB55MjpYpB8= -github.com/bytedance/gopkg v0.0.0-20210910103821-e4efae9c17c3/go.mod h1:birsdqRCbwnckJbdAvcSao+AzOyibVEoWB55MjpYpB8= github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7/go.mod h1:2ZlV9BaUH4+NXIBF0aMdKKAnHTzqH+iMU4KUjAbL23Q= -github.com/bytedance/gopkg v0.0.0-20220509134931-d1878f638986/go.mod h1:2ZlV9BaUH4+NXIBF0aMdKKAnHTzqH+iMU4KUjAbL23Q= github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b/go.mod h1:FtQG3YbQG9L/91pbKSw787yBQPutC+457AvDW77fgUQ= github.com/bytedance/gopkg v0.0.0-20240507064146-197ded923ae3/go.mod h1:FtQG3YbQG9L/91pbKSw787yBQPutC+457AvDW77fgUQ= github.com/bytedance/gopkg v0.0.0-20240514070511-01b2cbcf35e1 h1:rT7Mm6uUpHeZQzfs2v0Mlj0SL02CzyVi+EB7VYPM/z4= @@ -80,15 +73,12 @@ github.com/bytedance/sonic v1.11.8/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1 github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= -github.com/choleraehyq/pid v0.0.12/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U= -github.com/choleraehyq/pid v0.0.13/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -111,29 +101,17 @@ github.com/cloudwego/hertz v0.6.0/go.mod h1:83EedHQvCXpveYh2r9us8YlQ1C28vPg93wPd github.com/cloudwego/iasm v0.0.9/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= -github.com/cloudwego/kitex v0.0.4/go.mod h1:EIjPJ4Dom2ornk7xDCdKpUpOnf4Tulevimh4Tn05OGc= -github.com/cloudwego/kitex v0.1.4/go.mod h1:qxxpIUl5zvbcvcQeKrlm2t2f1BBxt4EPMksBUFwr6QA= -github.com/cloudwego/kitex v0.3.2/go.mod h1:/XD07VpUD9VQWmmoepASgZ6iw//vgWikVA9MpzLC5i0= github.com/cloudwego/kitex v0.10.3 h1:L3JRkb25oXMf1ROslQNY7E9EpaUBBjJWwjGfkQERJ+k= github.com/cloudwego/kitex v0.10.3/go.mod h1:6wYnJc0TpKnHwM8/Fcy2YrQNyrlmpMYP0y5ADZrqYsc= -github.com/cloudwego/kitex-examples v0.1.0/go.mod h1:QAouWRyHUup8O79re3fA/ac8jPOdTVWe9ZOlmaKd2U0= github.com/cloudwego/kitex-examples v0.3.3 h1:VkAHDmmWTY/3TY52yF9T8F/CKBT1wmssB2hnanqlWjM= github.com/cloudwego/kitex-examples v0.3.3/go.mod h1:bh79UiY/QiYL7MvmqAp7RVmNsIKmn66WpbOG47Jxwo8= github.com/cloudwego/localsession v0.0.2 h1:N9/IDtCPj1fCL9bCTP+DbXx3f40YjVYWcwkJG0YhQkY= github.com/cloudwego/localsession v0.0.2/go.mod h1:kiJxmvAcy4PLgKtEnPS5AXed3xCiXcs7Z+KBHP72Wv8= -github.com/cloudwego/netpoll v0.0.2/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8= -github.com/cloudwego/netpoll v0.0.3/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8= -github.com/cloudwego/netpoll v0.1.0/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8= -github.com/cloudwego/netpoll v0.1.2/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8= -github.com/cloudwego/netpoll v0.2.4/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzCx2KsnPI4E= github.com/cloudwego/netpoll v0.3.1/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzCx2KsnPI4E= github.com/cloudwego/netpoll v0.6.3 h1:t+ndlwBFjQZimUj3ul31DwI45t18eOr2pcK3juZZm+E= github.com/cloudwego/netpoll v0.6.3/go.mod h1:kaqvfZ70qd4T2WtIIpCOi5Cxyob8viEpzLhCrTrz3HM= -github.com/cloudwego/netpoll-http2 v0.0.4/go.mod h1:iFr5SzJCXIYgBg0ubL0fZiCQ6W36s9p0KjXpV04lmoY= -github.com/cloudwego/netpoll-http2 v0.0.6/go.mod h1:+bjPyu2Cd4GDzKa0IegPgp1hjMjpZ6/kXTsSjIsmUk8= github.com/cloudwego/runtimex v0.1.0 h1:HG+WxWoj5/CDChDZ7D99ROwvSMkuNXAqt6hnhTTZDiI= github.com/cloudwego/runtimex v0.1.0/go.mod h1:23vL/HGV0W8nSCHbe084AgEBdDV4rvXenEUMnUNvUd8= -github.com/cloudwego/thriftgo v0.1.2/go.mod h1:LzeafuLSiHA9JTiWC8TIMIq64iadeObgRUhmVG1OC/w= github.com/cloudwego/thriftgo v0.3.6/go.mod h1:29ukiySoAMd0vXMYIduAY9dph/7dmChvOS11YLotFb8= github.com/cloudwego/thriftgo v0.3.15 h1:yB/DDGjeSjliyidMVBjKhGl9RgE4M8iVIz5dKpAIyUs= github.com/cloudwego/thriftgo v0.3.15/go.mod h1:R4a+4aVDI0V9YCTfpNgmvbkq/9ThKgF7Om8Z0I36698= @@ -143,7 +121,6 @@ github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XP github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= @@ -297,9 +274,6 @@ github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+ github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kitex-contrib/polaris v0.0.0-20220811095956-d405002eaeaf h1:4EL5Z4MGH7uBlAGxHttXXExjnjt4sfheb0Sk7GO0KV8= -github.com/kitex-contrib/polaris v0.0.0-20220811095956-d405002eaeaf/go.mod h1:/MoPbBzpGpoMtIIJ3vyqV0bUAe0PRWu/VHMPTjflz1A= -github.com/kitex-contrib/tracer-opentracing v0.0.2/go.mod h1:mprt5pxqywFQxlHb7ugfiMdKbABTLI9YrBYs9WmlK5Q= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= @@ -332,13 +306,11 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso= github.com/nyaruka/phonenumbers v1.0.55 h1:bj0nTO88Y68KeUQ/n3Lo2KgK7lM1hF7L9NFuwcCl3yg= github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U= github.com/oleiade/lane v1.0.1 h1:hXofkn7GEOubzTwNpeL9MaNy8WxolCYb9cInAIeqShU= github.com/oleiade/lane v1.0.1/go.mod h1:IyTkraa4maLfjq/GmHR+Dxb4kCMtEGeb+qmhlrQ5Mk4= -github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY= github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= @@ -348,7 +320,6 @@ 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/polaris-go v1.2.0-beta.0.0.20220625150934-9ebd65d7dd37/go.mod h1:xXTl4b5ybYkwvXZA+nc1HNyLK/bsHUg08R4ewTa9axc= github.com/polarismesh/polaris-go v1.3.0 h1:KZKX//ow4OPPoS5+s7h07ptprg+2AcNVGrN6WakC9QM= github.com/polarismesh/polaris-go v1.3.0/go.mod h1:HsN0ierETIujHpmnnYJ3qkwQw4QGAECuHvBZTDaw1tI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -390,7 +361,6 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -403,7 +373,6 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= @@ -419,8 +388,6 @@ github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/uber/jaeger-client-go v2.29.1+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= -github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -435,7 +402,6 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.8.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= @@ -454,7 +420,6 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -540,7 +505,6 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= @@ -566,7 +530,6 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= @@ -610,13 +573,11 @@ golang.org/x/sys v0.0.0-20210304124612-50617c2ba197/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -818,7 +779,6 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/registry/zookeeper/go.sum b/registry/zookeeper/go.sum index c493f52..283d86e 100644 --- a/registry/zookeeper/go.sum +++ b/registry/zookeeper/go.sum @@ -4,7 +4,6 @@ gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zum git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY= github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= @@ -15,8 +14,6 @@ github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/bytedance/go-tagexpr/v2 v2.9.2 h1:QySJaAIQgOEDQBLS3x9BxOWrnhqu5sQ+f6HaZIxD39I= github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM= -github.com/bytedance/gopkg v0.0.0-20210705062217-74c74ebadcae/go.mod h1:birsdqRCbwnckJbdAvcSao+AzOyibVEoWB55MjpYpB8= -github.com/bytedance/gopkg v0.0.0-20210709064845-3c00f9323f09/go.mod h1:birsdqRCbwnckJbdAvcSao+AzOyibVEoWB55MjpYpB8= github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7/go.mod h1:2ZlV9BaUH4+NXIBF0aMdKKAnHTzqH+iMU4KUjAbL23Q= github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b/go.mod h1:FtQG3YbQG9L/91pbKSw787yBQPutC+457AvDW77fgUQ= github.com/bytedance/gopkg v0.0.0-20240507064146-197ded923ae3/go.mod h1:FtQG3YbQG9L/91pbKSw787yBQPutC+457AvDW77fgUQ= @@ -30,7 +27,6 @@ github.com/bytedance/sonic v1.11.8/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1 github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= @@ -48,18 +44,14 @@ github.com/cloudwego/hertz v0.6.0/go.mod h1:83EedHQvCXpveYh2r9us8YlQ1C28vPg93wPd github.com/cloudwego/iasm v0.0.9/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= -github.com/cloudwego/kitex v0.0.1/go.mod h1:NTTu8szFfMKY9pxa7JmI/4FZpD15p5YUHLTYMqsXj9o= github.com/cloudwego/kitex v0.10.3 h1:L3JRkb25oXMf1ROslQNY7E9EpaUBBjJWwjGfkQERJ+k= github.com/cloudwego/kitex v0.10.3/go.mod h1:6wYnJc0TpKnHwM8/Fcy2YrQNyrlmpMYP0y5ADZrqYsc= github.com/cloudwego/localsession v0.0.2/go.mod h1:kiJxmvAcy4PLgKtEnPS5AXed3xCiXcs7Z+KBHP72Wv8= -github.com/cloudwego/netpoll v0.0.2/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8= github.com/cloudwego/netpoll v0.3.1/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzCx2KsnPI4E= github.com/cloudwego/netpoll v0.6.3 h1:t+ndlwBFjQZimUj3ul31DwI45t18eOr2pcK3juZZm+E= github.com/cloudwego/netpoll v0.6.3/go.mod h1:kaqvfZ70qd4T2WtIIpCOi5Cxyob8viEpzLhCrTrz3HM= -github.com/cloudwego/netpoll-http2 v0.0.4/go.mod h1:iFr5SzJCXIYgBg0ubL0fZiCQ6W36s9p0KjXpV04lmoY= github.com/cloudwego/runtimex v0.1.0 h1:HG+WxWoj5/CDChDZ7D99ROwvSMkuNXAqt6hnhTTZDiI= github.com/cloudwego/runtimex v0.1.0/go.mod h1:23vL/HGV0W8nSCHbe084AgEBdDV4rvXenEUMnUNvUd8= -github.com/cloudwego/thriftgo v0.0.1/go.mod h1:LzeafuLSiHA9JTiWC8TIMIq64iadeObgRUhmVG1OC/w= github.com/cloudwego/thriftgo v0.3.6/go.mod h1:29ukiySoAMd0vXMYIduAY9dph/7dmChvOS11YLotFb8= github.com/cloudwego/thriftgo v0.3.15/go.mod h1:R4a+4aVDI0V9YCTfpNgmvbkq/9ThKgF7Om8Z0I36698= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -88,7 +80,6 @@ github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2C github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpxhq9o2S/CELCSUxEWWAuoCUcVCQWv7G2OCk= github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= -github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/go-zookeeper/zk v1.0.3 h1:7M2kwOsc//9VeeFiPtf+uSJlVpU66x9Ba5+8XK7/TDg= github.com/go-zookeeper/zk v1.0.3/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= @@ -131,15 +122,12 @@ github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8/go.mod h1:Nhe/D github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= github.com/jhump/protoreflect v1.8.2/go.mod h1:7GcYQDdMU/O/BBrl/cX6PNHpXh6cenjd8pneu5yW7Tg= -github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kitex-contrib/registry-zookeeper v0.0.0-20240813065530-bfdecef3f6bd h1:xW271Yw6e912hXLuZrNm+/eM1a0Wz4n7GiIVDM6fA+w= -github.com/kitex-contrib/registry-zookeeper v0.0.0-20240813065530-bfdecef3f6bd/go.mod h1:7U6Kk7lRyfCX4JNaNmjpYbjdNgS+utZWKb5w28rZ6r0= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= @@ -152,7 +140,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/gls v0.0.0-20220109145502-612d0167dce5/go.mod h1:I8AX+yW//L8Hshx6+a1m3bYkwXkpsVjA2795vP4f4oQ= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso= @@ -170,7 +157,6 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1: github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w= github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -206,7 +192,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -254,7 +239,6 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= @@ -285,7 +269,6 @@ golang.org/x/sys v0.0.0-20210304124612-50617c2ba197/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -382,7 +365,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=