Skip to content
Snippets Groups Projects
Commit a1cdbde6 authored by 邹毅贤's avatar 邹毅贤
Browse files

format code

parent 1b28063e
Branches
Tags
No related merge requests found
...@@ -24,24 +24,29 @@ import ( ...@@ -24,24 +24,29 @@ import (
import ( import (
"github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/config_center" . "github.com/apache/dubbo-go/config_center"
"github.com/apache/dubbo-go/config_center/parser" "github.com/apache/dubbo-go/config_center/parser"
) )
func init() { func init() {
extension.SetConfigCenterFactory("apollo", func() config_center.DynamicConfigurationFactory { return &apolloDynamicConfigurationFactory{} }) extension.SetConfigCenterFactory("apollo", createDynamicConfigurationFactory)
} }
type apolloDynamicConfigurationFactory struct { func createDynamicConfigurationFactory() DynamicConfigurationFactory {
return &apolloConfigurationFactory{}
} }
var once sync.Once type apolloConfigurationFactory struct{}
var dynamicConfiguration *apolloDynamicConfiguration
func (f *apolloDynamicConfigurationFactory) GetDynamicConfiguration(url *common.URL) (config_center.DynamicConfiguration, error) { var (
once sync.Once
dynamicConfiguration *apolloConfiguration
)
func (f *apolloConfigurationFactory) GetDynamicConfiguration(url *common.URL) (DynamicConfiguration, error) {
var err error var err error
once.Do(func() { once.Do(func() {
dynamicConfiguration, err = newApolloDynamicConfiguration(url) dynamicConfiguration, err = newApolloConfiguration(url)
}) })
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -26,7 +26,7 @@ import ( ...@@ -26,7 +26,7 @@ import (
"github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/config_center" . "github.com/apache/dubbo-go/config_center"
"github.com/apache/dubbo-go/config_center/parser" "github.com/apache/dubbo-go/config_center/parser"
"github.com/apache/dubbo-go/remoting" "github.com/apache/dubbo-go/remoting"
...@@ -38,7 +38,7 @@ const ( ...@@ -38,7 +38,7 @@ const (
apolloConfigFormat = "%s.%s" apolloConfigFormat = "%s.%s"
) )
type apolloDynamicConfiguration struct { type apolloConfiguration struct {
url *common.URL url *common.URL
listeners sync.Map listeners sync.Map
...@@ -46,15 +46,15 @@ type apolloDynamicConfiguration struct { ...@@ -46,15 +46,15 @@ type apolloDynamicConfiguration struct {
parser parser.ConfigurationParser parser parser.ConfigurationParser
} }
func newApolloDynamicConfiguration(url *common.URL) (*apolloDynamicConfiguration, error) { func newApolloConfiguration(url *common.URL) (*apolloConfiguration, error) {
c := &apolloDynamicConfiguration{ c := &apolloConfiguration{
url: url, url: url,
} }
configAddr := c.getAddressWithProtocolPrefix(url) configAddr := c.getAddressWithProtocolPrefix(url)
configCluster := url.GetParam(constant.CONFIG_CLUSTER_KEY, "") configCluster := url.GetParam(constant.CONFIG_CLUSTER_KEY, "")
appId := url.GetParam(constant.CONFIG_GROUP_KEY, config_center.DEFAULT_GROUP) appId := url.GetParam(constant.CONFIG_GROUP_KEY, DEFAULT_GROUP)
namespaces := url.GetParam(constant.CONFIG_NAMESPACE_KEY, getProperties(config_center.DEFAULT_GROUP)) namespaces := url.GetParam(constant.CONFIG_NAMESPACE_KEY, getProperties(DEFAULT_GROUP))
readyConfig := &agollo.AppConfig{ readyConfig := &agollo.AppConfig{
AppId: appId, AppId: appId,
Cluster: configCluster, Cluster: configCluster,
...@@ -82,8 +82,8 @@ func getChangeType(change agollo.ConfigChangeType) remoting.EventType { ...@@ -82,8 +82,8 @@ func getChangeType(change agollo.ConfigChangeType) remoting.EventType {
} }
} }
func (c *apolloDynamicConfiguration) AddListener(key string, listener config_center.ConfigurationListener, opts ...config_center.Option) { func (c *apolloConfiguration) AddListener(key string, listener ConfigurationListener, opts ...Option) {
k := &config_center.Options{} k := &Options{}
for _, opt := range opts { for _, opt := range opts {
opt(k) opt(k)
} }
...@@ -93,8 +93,8 @@ func (c *apolloDynamicConfiguration) AddListener(key string, listener config_cen ...@@ -93,8 +93,8 @@ func (c *apolloDynamicConfiguration) AddListener(key string, listener config_cen
l.(*apolloListener).AddListener(listener) l.(*apolloListener).AddListener(listener)
} }
func (c *apolloDynamicConfiguration) RemoveListener(key string, listener config_center.ConfigurationListener, opts ...config_center.Option) { func (c *apolloConfiguration) RemoveListener(key string, listener ConfigurationListener, opts ...Option) {
k := &config_center.Options{} k := &Options{}
for _, opt := range opts { for _, opt := range opts {
opt(k) opt(k)
} }
...@@ -114,12 +114,12 @@ func getNamespaceName(namespace string, configFileFormat agollo.ConfigFileFormat ...@@ -114,12 +114,12 @@ func getNamespaceName(namespace string, configFileFormat agollo.ConfigFileFormat
return fmt.Sprintf(apolloConfigFormat, namespace, configFileFormat) return fmt.Sprintf(apolloConfigFormat, namespace, configFileFormat)
} }
func (c *apolloDynamicConfiguration) GetConfig(key string, opts ...config_center.Option) (string, error) { func (c *apolloConfiguration) GetConfig(key string, opts ...Option) (string, error) {
k := &config_center.Options{} k := &Options{}
for _, opt := range opts { for _, opt := range opts {
opt(k) opt(k)
} }
namespace := c.url.GetParam(constant.CONFIG_NAMESPACE_KEY, getProperties(config_center.DEFAULT_GROUP)) namespace := c.url.GetParam(constant.CONFIG_NAMESPACE_KEY, getProperties(DEFAULT_GROUP))
config := agollo.GetConfig(namespace) config := agollo.GetConfig(namespace)
if config == nil { if config == nil {
return "", errors.New(fmt.Sprintf("nothiing in namespace:%s ", namespace)) return "", errors.New(fmt.Sprintf("nothiing in namespace:%s ", namespace))
...@@ -127,7 +127,7 @@ func (c *apolloDynamicConfiguration) GetConfig(key string, opts ...config_center ...@@ -127,7 +127,7 @@ func (c *apolloDynamicConfiguration) GetConfig(key string, opts ...config_center
return config.GetContent(agollo.Properties), nil return config.GetContent(agollo.Properties), nil
} }
func (c *apolloDynamicConfiguration) getAddressWithProtocolPrefix(url *common.URL) string { func (c *apolloConfiguration) getAddressWithProtocolPrefix(url *common.URL) string {
address := url.Location address := url.Location
converted := address converted := address
if len(address) != 0 { if len(address) != 0 {
...@@ -145,13 +145,13 @@ func (c *apolloDynamicConfiguration) getAddressWithProtocolPrefix(url *common.UR ...@@ -145,13 +145,13 @@ func (c *apolloDynamicConfiguration) getAddressWithProtocolPrefix(url *common.UR
return converted return converted
} }
func (c *apolloDynamicConfiguration) Parser() parser.ConfigurationParser { func (c *apolloConfiguration) Parser() parser.ConfigurationParser {
return c.parser return c.parser
} }
func (c *apolloDynamicConfiguration) SetParser(p parser.ConfigurationParser) { func (c *apolloConfiguration) SetParser(p parser.ConfigurationParser) {
c.parser = p c.parser = p
} }
func (c *apolloDynamicConfiguration) GetConfigs(key string, opts ...config_center.Option) (string, error) { func (c *apolloConfiguration) GetConfigs(key string, opts ...Option) (string, error) {
return c.GetConfig(key, opts...) return c.GetConfig(key, opts...)
} }
...@@ -100,7 +100,7 @@ func Test_GetConfig(t *testing.T) { ...@@ -100,7 +100,7 @@ func Test_GetConfig(t *testing.T) {
assert.Equal(t, "ikurento.com", mapContent["application.organization"]) assert.Equal(t, "ikurento.com", mapContent["application.organization"])
} }
func initMockApollo(t *testing.T) *apolloDynamicConfiguration { func initMockApollo(t *testing.T) *apolloConfiguration {
c := &config.BaseConfig{ConfigCenterConfig: &config.ConfigCenterConfig{ c := &config.BaseConfig{ConfigCenterConfig: &config.ConfigCenterConfig{
Protocol: "apollo", Protocol: "apollo",
Address: "106.12.25.204:8080", Address: "106.12.25.204:8080",
...@@ -112,7 +112,7 @@ func initMockApollo(t *testing.T) *apolloDynamicConfiguration { ...@@ -112,7 +112,7 @@ func initMockApollo(t *testing.T) *apolloDynamicConfiguration {
apolloUrl := strings.ReplaceAll(apollo.URL, "http", "apollo") apolloUrl := strings.ReplaceAll(apollo.URL, "http", "apollo")
url, err := common.NewURL(context.TODO(), apolloUrl, common.WithParams(c.ConfigCenterConfig.GetUrlMap())) url, err := common.NewURL(context.TODO(), apolloUrl, common.WithParams(c.ConfigCenterConfig.GetUrlMap()))
assert.NoError(t, err) assert.NoError(t, err)
configuration, err := newApolloDynamicConfiguration(&url) configuration, err := newApolloConfiguration(&url)
assert.NoError(t, err) assert.NoError(t, err)
return configuration return configuration
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment