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

format code

parent 4d10d24e
No related branches found
No related tags found
No related merge requests found
......@@ -24,24 +24,29 @@ import (
import (
"github.com/apache/dubbo-go/common"
"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"
)
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
var dynamicConfiguration *apolloDynamicConfiguration
type apolloConfigurationFactory struct{}
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
once.Do(func() {
dynamicConfiguration, err = newApolloDynamicConfiguration(url)
dynamicConfiguration, err = newApolloConfiguration(url)
})
if err != nil {
return nil, err
......
......@@ -26,7 +26,7 @@ import (
"github.com/apache/dubbo-go/common"
"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/remoting"
......@@ -38,7 +38,7 @@ const (
apolloConfigFormat = "%s.%s"
)
type apolloDynamicConfiguration struct {
type apolloConfiguration struct {
url *common.URL
listeners sync.Map
......@@ -46,15 +46,15 @@ type apolloDynamicConfiguration struct {
parser parser.ConfigurationParser
}
func newApolloDynamicConfiguration(url *common.URL) (*apolloDynamicConfiguration, error) {
c := &apolloDynamicConfiguration{
func newApolloConfiguration(url *common.URL) (*apolloConfiguration, error) {
c := &apolloConfiguration{
url: url,
}
configAddr := c.getAddressWithProtocolPrefix(url)
configCluster := url.GetParam(constant.CONFIG_CLUSTER_KEY, "")
appId := url.GetParam(constant.CONFIG_GROUP_KEY, config_center.DEFAULT_GROUP)
namespaces := url.GetParam(constant.CONFIG_NAMESPACE_KEY, getProperties(config_center.DEFAULT_GROUP))
appId := url.GetParam(constant.CONFIG_GROUP_KEY, DEFAULT_GROUP)
namespaces := url.GetParam(constant.CONFIG_NAMESPACE_KEY, getProperties(DEFAULT_GROUP))
readyConfig := &agollo.AppConfig{
AppId: appId,
Cluster: configCluster,
......@@ -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) {
k := &config_center.Options{}
func (c *apolloConfiguration) AddListener(key string, listener ConfigurationListener, opts ...Option) {
k := &Options{}
for _, opt := range opts {
opt(k)
}
......@@ -93,8 +93,8 @@ func (c *apolloDynamicConfiguration) AddListener(key string, listener config_cen
l.(*apolloListener).AddListener(listener)
}
func (c *apolloDynamicConfiguration) RemoveListener(key string, listener config_center.ConfigurationListener, opts ...config_center.Option) {
k := &config_center.Options{}
func (c *apolloConfiguration) RemoveListener(key string, listener ConfigurationListener, opts ...Option) {
k := &Options{}
for _, opt := range opts {
opt(k)
}
......@@ -114,12 +114,12 @@ func getNamespaceName(namespace string, configFileFormat agollo.ConfigFileFormat
return fmt.Sprintf(apolloConfigFormat, namespace, configFileFormat)
}
func (c *apolloDynamicConfiguration) GetConfig(key string, opts ...config_center.Option) (string, error) {
k := &config_center.Options{}
func (c *apolloConfiguration) GetConfig(key string, opts ...Option) (string, error) {
k := &Options{}
for _, opt := range opts {
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)
if config == nil {
return "", errors.New(fmt.Sprintf("nothiing in namespace:%s ", namespace))
......@@ -127,7 +127,7 @@ func (c *apolloDynamicConfiguration) GetConfig(key string, opts ...config_center
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
converted := address
if len(address) != 0 {
......@@ -145,13 +145,13 @@ func (c *apolloDynamicConfiguration) getAddressWithProtocolPrefix(url *common.UR
return converted
}
func (c *apolloDynamicConfiguration) Parser() parser.ConfigurationParser {
func (c *apolloConfiguration) Parser() parser.ConfigurationParser {
return c.parser
}
func (c *apolloDynamicConfiguration) SetParser(p parser.ConfigurationParser) {
func (c *apolloConfiguration) SetParser(p parser.ConfigurationParser) {
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...)
}
......@@ -100,7 +100,7 @@ func Test_GetConfig(t *testing.T) {
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{
Protocol: "apollo",
Address: "106.12.25.204:8080",
......@@ -112,7 +112,7 @@ func initMockApollo(t *testing.T) *apolloDynamicConfiguration {
apolloUrl := strings.ReplaceAll(apollo.URL, "http", "apollo")
url, err := common.NewURL(context.TODO(), apolloUrl, common.WithParams(c.ConfigCenterConfig.GetUrlMap()))
assert.NoError(t, err)
configuration, err := newApolloDynamicConfiguration(&url)
configuration, err := newApolloConfiguration(&url)
assert.NoError(t, err)
return configuration
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment