Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
a1cdbde6
Commit
a1cdbde6
authored
Nov 5, 2019
by
邹毅贤
Browse files
Options
Downloads
Patches
Plain Diff
format code
parent
1b28063e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
config_center/apollo/factory.go
+12
-7
12 additions, 7 deletions
config_center/apollo/factory.go
config_center/apollo/impl.go
+17
-17
17 additions, 17 deletions
config_center/apollo/impl.go
config_center/apollo/impl_test.go
+2
-2
2 additions, 2 deletions
config_center/apollo/impl_test.go
with
31 additions
and
26 deletions
config_center/apollo/factory.go
+
12
−
7
View file @
a1cdbde6
...
@@ -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
&
apollo
DynamicConfigurationFactory
{}
}
)
extension
.
SetConfigCenterFactory
(
"apollo"
,
create
DynamicConfigurationFactory
)
}
}
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
=
newApollo
Dynamic
Configuration
(
url
)
dynamicConfiguration
,
err
=
newApolloConfiguration
(
url
)
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
This diff is collapsed.
Click to expand it.
config_center/apollo/impl.go
+
17
−
17
View file @
a1cdbde6
...
@@ -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
apollo
Dynamic
Configuration
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
newApollo
Dynamic
Configuration
(
url
*
common
.
URL
)
(
*
apollo
Dynamic
Configuration
,
error
)
{
func
newApolloConfiguration
(
url
*
common
.
URL
)
(
*
apolloConfiguration
,
error
)
{
c
:=
&
apollo
Dynamic
Configuration
{
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
*
apollo
Dynamic
Configuration
)
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
*
apollo
Dynamic
Configuration
)
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
*
apollo
Dynamic
Configuration
)
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
*
apollo
Dynamic
Configuration
)
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
*
apollo
Dynamic
Configuration
)
Parser
()
parser
.
ConfigurationParser
{
func
(
c
*
apolloConfiguration
)
Parser
()
parser
.
ConfigurationParser
{
return
c
.
parser
return
c
.
parser
}
}
func
(
c
*
apollo
Dynamic
Configuration
)
SetParser
(
p
parser
.
ConfigurationParser
)
{
func
(
c
*
apolloConfiguration
)
SetParser
(
p
parser
.
ConfigurationParser
)
{
c
.
parser
=
p
c
.
parser
=
p
}
}
func
(
c
*
apollo
Dynamic
Configuration
)
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
...
)
}
}
This diff is collapsed.
Click to expand it.
config_center/apollo/impl_test.go
+
2
−
2
View file @
a1cdbde6
...
@@ -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
)
*
apollo
Dynamic
Configuration
{
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
:=
newApollo
Dynamic
Configuration
(
&
url
)
configuration
,
err
:=
newApolloConfiguration
(
&
url
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
return
configuration
return
configuration
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment