Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
2246a4e4
Commit
2246a4e4
authored
5 years ago
by
邹毅贤
Browse files
Options
Downloads
Patches
Plain Diff
format code
parent
4d10d24e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide 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 @
2246a4e4
...
...
@@ -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
&
apollo
DynamicConfigurationFactory
{}
}
)
extension
.
SetConfigCenterFactory
(
"apollo"
,
create
DynamicConfigurationFactory
)
}
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
=
newApollo
Dynamic
Configuration
(
url
)
dynamicConfiguration
,
err
=
newApolloConfiguration
(
url
)
})
if
err
!=
nil
{
return
nil
,
err
...
...
This diff is collapsed.
Click to expand it.
config_center/apollo/impl.go
+
17
−
17
View file @
2246a4e4
...
...
@@ -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
apollo
Dynamic
Configuration
struct
{
type
apolloConfiguration
struct
{
url
*
common
.
URL
listeners
sync
.
Map
...
...
@@ -46,15 +46,15 @@ type apolloDynamicConfiguration struct {
parser
parser
.
ConfigurationParser
}
func
newApollo
Dynamic
Configuration
(
url
*
common
.
URL
)
(
*
apollo
Dynamic
Configuration
,
error
)
{
c
:=
&
apollo
Dynamic
Configuration
{
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
*
apollo
Dynamic
Configuration
)
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
*
apollo
Dynamic
Configuration
)
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
*
apollo
Dynamic
Configuration
)
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
*
apollo
Dynamic
Configuration
)
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
*
apollo
Dynamic
Configuration
)
Parser
()
parser
.
ConfigurationParser
{
func
(
c
*
apolloConfiguration
)
Parser
()
parser
.
ConfigurationParser
{
return
c
.
parser
}
func
(
c
*
apollo
Dynamic
Configuration
)
SetParser
(
p
parser
.
ConfigurationParser
)
{
func
(
c
*
apolloConfiguration
)
SetParser
(
p
parser
.
ConfigurationParser
)
{
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
...
)
}
This diff is collapsed.
Click to expand it.
config_center/apollo/impl_test.go
+
2
−
2
View file @
2246a4e4
...
...
@@ -100,7 +100,7 @@ func Test_GetConfig(t *testing.T) {
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
{
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
:=
newApollo
Dynamic
Configuration
(
&
url
)
configuration
,
err
:=
newApolloConfiguration
(
&
url
)
assert
.
NoError
(
t
,
err
)
return
configuration
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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