Skip to content
Snippets Groups Projects
Commit 7e490178 authored by 邹毅贤's avatar 邹毅贤 Committed by GitHub
Browse files

Merge pull request #545 from YuzeZhang/master

Add comments for config_center
parents dd97fccd a780a757
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ type apolloListener struct {
listeners map[config_center.ConfigurationListener]struct{}
}
// NewApolloListener ...
// NewApolloListener creates a new apolloListener
func NewApolloListener() *apolloListener {
return &apolloListener{
listeners: make(map[config_center.ConfigurationListener]struct{}, 0),
......@@ -49,7 +49,7 @@ func (a *apolloListener) OnChange(changeEvent *agollo.ChangeEvent) {
}
}
// AddListener ...
// AddListener adds a listener for apollo
func (a *apolloListener) AddListener(l config_center.ConfigurationListener) {
if _, ok := a.listeners[l]; !ok {
a.listeners[l] = struct{}{}
......@@ -57,7 +57,7 @@ func (a *apolloListener) AddListener(l config_center.ConfigurationListener) {
}
}
// RemoveListener ...
// RemoveListener removes listeners of apollo
func (a *apolloListener) RemoveListener(l config_center.ConfigurationListener) {
delete(a.listeners, l)
}
......@@ -25,12 +25,12 @@ import (
"github.com/apache/dubbo-go/remoting"
)
// ConfigurationListener ...
// ConfigurationListener for changing listener's event
type ConfigurationListener interface {
Process(*ConfigChangeEvent)
}
// ConfigChangeEvent ...
// ConfigChangeEvent for changing listener's event
type ConfigChangeEvent struct {
Key string
Value interface{}
......
......@@ -21,7 +21,7 @@ import (
"github.com/apache/dubbo-go/common"
)
// Configurator ...
// Configurator supports GetUrl and constructor
type Configurator interface {
GetUrl() *common.URL
Configure(url *common.URL)
......
......@@ -23,7 +23,7 @@ import (
"github.com/apache/dubbo-go/config_center"
)
// NewMockConfigurator ...
// NewMockConfigurator creates a new mockConfigurator
func NewMockConfigurator(url *common.URL) config_center.Configurator {
return &mockConfigurator{configuratorUrl: url}
}
......@@ -32,12 +32,12 @@ type mockConfigurator struct {
configuratorUrl *common.URL
}
// GetUrl ...
// GetUrl gets a configuratorUrl
func (c *mockConfigurator) GetUrl() *common.URL {
return c.configuratorUrl
}
// Configure ...
// Configure sets up param CLUSTER_KEY and cluster for url
func (c *mockConfigurator) Configure(url *common.URL) {
if cluster := c.GetUrl().GetParam(constant.CLUSTER_KEY, ""); cluster != "" {
url.SetParam(constant.CLUSTER_KEY, cluster)
......
......@@ -40,7 +40,7 @@ const (
DEFAULT_CONFIG_TIMEOUT = "10s"
)
// DynamicConfiguration ...
// DynamicConfiguration for modify listener and get properties file
type DynamicConfiguration interface {
Parser() parser.ConfigurationParser
SetParser(parser.ConfigurationParser)
......@@ -71,14 +71,14 @@ type Options struct {
// Option ...
type Option func(*Options)
// WithGroup ...
// WithGroup assigns group to opt.Group
func WithGroup(group string) Option {
return func(opt *Options) {
opt.Group = group
}
}
// WithTimeout ...
// WithTimeout assigns time to opt.Timeout
func WithTimeout(time time.Duration) Option {
return func(opt *Options) {
opt.Timeout = time
......
......@@ -21,7 +21,7 @@ import (
"github.com/apache/dubbo-go/common"
)
// DynamicConfigurationFactory ...
// DynamicConfigurationFactory gets the DynamicConfiguration
type DynamicConfigurationFactory interface {
GetDynamicConfiguration(*common.URL) (DynamicConfiguration, error)
}
......@@ -43,7 +43,7 @@ var (
dynamicConfiguration *MockDynamicConfiguration
)
// GetDynamicConfiguration ...
// GetDynamicConfiguration returns a DynamicConfiguration
func (f *MockDynamicConfigurationFactory) GetDynamicConfiguration(_ *common.URL) (DynamicConfiguration, error) {
var err error
once.Do(func() {
......@@ -99,16 +99,16 @@ type MockDynamicConfiguration struct {
listener map[string]ConfigurationListener
}
// AddListener ...
// AddListener adds a listener for MockDynamicConfiguration
func (c *MockDynamicConfiguration) AddListener(key string, listener ConfigurationListener, _ ...Option) {
c.listener[key] = listener
}
// RemoveListener ...
// RemoveListener removes the listener for MockDynamicConfiguration
func (c *MockDynamicConfiguration) RemoveListener(_ string, _ ConfigurationListener, _ ...Option) {
}
// GetConfig ...
// GetConfig returns content of MockDynamicConfiguration
func (c *MockDynamicConfiguration) GetConfig(_ string, _ ...Option) (string, error) {
return c.content, nil
......@@ -119,17 +119,17 @@ func (c *MockDynamicConfiguration) GetConfigs(key string, opts ...Option) (strin
return c.GetConfig(key, opts...)
}
// Parser ...
// Parser returns a parser of MockDynamicConfiguration
func (c *MockDynamicConfiguration) Parser() parser.ConfigurationParser {
return c.parser
}
// SetParser ...
// SetParser sets parser of MockDynamicConfiguration
func (c *MockDynamicConfiguration) SetParser(p parser.ConfigurationParser) {
c.parser = p
}
// GetProperties ...
// GetProperties gets content of MockDynamicConfiguration
func (c *MockDynamicConfiguration) GetProperties(_ string, _ ...Option) (string, error) {
return c.content, nil
}
......@@ -139,7 +139,7 @@ func (c *MockDynamicConfiguration) GetInternalProperty(key string, opts ...Optio
return c.GetProperties(key, opts...)
}
// GetRule ...
// GetRule gets properties of MockDynamicConfiguration
func (c *MockDynamicConfiguration) GetRule(key string, opts ...Option) (string, error) {
return c.GetProperties(key, opts...)
}
......
......@@ -47,7 +47,7 @@ type ConfigurationParser interface {
ParseToUrls(content string) ([]*common.URL, error)
}
// DefaultConfigurationParser for support properties file in config center
// DefaultConfigurationParser for supporting properties file in config center
type DefaultConfigurationParser struct{}
// ConfiguratorConfig ...
......@@ -71,7 +71,7 @@ type ConfigItem struct {
Side string `yaml:"side"`
}
// Parse ...
// Parse load content
func (parser *DefaultConfigurationParser) Parse(content string) (map[string]string, error) {
pps, err := properties.LoadString(content)
if err != nil {
......
......@@ -33,12 +33,12 @@ type CacheListener struct {
rootPath string
}
// NewCacheListener ...
// NewCacheListener creates a new CacheListener
func NewCacheListener(rootPath string) *CacheListener {
return &CacheListener{rootPath: rootPath}
}
// AddListener ...
// AddListener will add a listener if loaded
func (l *CacheListener) AddListener(key string, listener config_center.ConfigurationListener) {
// reference from https://stackoverflow.com/questions/34018908/golang-why-dont-we-have-a-set-datastructure
......@@ -50,7 +50,7 @@ func (l *CacheListener) AddListener(key string, listener config_center.Configura
}
}
// RemoveListener ...
// RemoveListener will delete a listener if loaded
func (l *CacheListener) RemoveListener(key string, listener config_center.ConfigurationListener) {
listeners, loaded := l.keyListeners.Load(key)
if loaded {
......@@ -58,7 +58,7 @@ func (l *CacheListener) RemoveListener(key string, listener config_center.Config
}
}
// DataChange ...
// DataChange changes all listeners' event
func (l *CacheListener) DataChange(event remoting.Event) bool {
if event.Content == "" {
//meanings new node
......
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