Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comments for config_center #545

Merged
merged 1 commit into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config_center/apollo/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -49,15 +49,15 @@ 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{}{}
agollo.AddChangeListener(a)
}
}

// RemoveListener ...
// RemoveListener removes listeners of apollo
func (a *apolloListener) RemoveListener(l config_center.ConfigurationListener) {
delete(a.listeners, l)
}
4 changes: 2 additions & 2 deletions config_center/configuration_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion config_center/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions config_center/configurator/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions config_center/dynamic_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
DEFAULT_CONFIG_TIMEOUT = "10s"
)

// DynamicConfiguration ...
// DynamicConfiguration for modify listener and get properties file
type DynamicConfiguration interface {
Parser() parser.ConfigurationParser
SetParser(parser.ConfigurationParser)
Expand All @@ -61,14 +61,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
Expand Down
2 changes: 1 addition & 1 deletion config_center/dynamic_configuration_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/apache/dubbo-go/common"
)

// DynamicConfigurationFactory ...
// DynamicConfigurationFactory gets the DynamicConfiguration
type DynamicConfigurationFactory interface {
GetDynamicConfiguration(*common.URL) (DynamicConfiguration, error)
}
16 changes: 8 additions & 8 deletions config_center/mock_dynamic_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
dynamicConfiguration *MockDynamicConfiguration
)

// GetDynamicConfiguration ...
// GetDynamicConfiguration returns a DynamicConfiguration
func (f *MockDynamicConfigurationFactory) GetDynamicConfiguration(_ *common.URL) (DynamicConfiguration, error) {
var err error
once.Do(func() {
Expand Down Expand Up @@ -88,16 +88,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
Expand All @@ -108,17 +108,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
}
Expand All @@ -128,7 +128,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...)
}
Expand Down
4 changes: 2 additions & 2 deletions config_center/parser/configuration_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions config_center/zookeeper/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,15 +50,15 @@ 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 {
delete(listeners.(map[config_center.ConfigurationListener]struct{}), listener)
}
}

// DataChange ...
// DataChange changes all listeners' event
func (l *CacheListener) DataChange(event remoting.Event) bool {
if event.Content == "" {
//meanings new node
Expand Down