Skip to content
Snippets Groups Projects
Commit 6c61c91e authored by Xin.Zh's avatar Xin.Zh Committed by GitHub
Browse files

Merge pull request #333 from weiwei-xiao/feature/add_comment_for_exported_by_golint

GOLINT: add comment for exported (checked by golint)
parents 2cf097e8 62db65d1
No related branches found
No related tags found
No related merge requests found
Showing
with 84 additions and 4 deletions
......@@ -21,6 +21,7 @@ import (
"github.com/apache/dubbo-go/common"
)
// Configurator ...
type Configurator interface {
GetUrl() *common.URL
Configure(url *common.URL)
......
......@@ -22,6 +22,7 @@ import (
"github.com/apache/dubbo-go/config_center"
)
// NewMockConfigurator ...
func NewMockConfigurator(url *common.URL) config_center.Configurator {
return &mockConfigurator{configuratorUrl: url}
}
......
......@@ -31,6 +31,7 @@ import (
const DEFAULT_GROUP = "dubbo"
const DEFAULT_CONFIG_TIMEOUT = "10s"
// DynamicConfiguration ...
type DynamicConfiguration interface {
Parser() parser.ConfigurationParser
SetParser(parser.ConfigurationParser)
......@@ -46,19 +47,23 @@ type DynamicConfiguration interface {
GetInternalProperty(string, ...Option) (string, error)
}
// Options ...
type Options struct {
Group string
Timeout time.Duration
}
// Option ...
type Option func(*Options)
// WithGroup ...
func WithGroup(group string) Option {
return func(opt *Options) {
opt.Group = group
}
}
// WithTimeout ...
func WithTimeout(time time.Duration) Option {
return func(opt *Options) {
opt.Timeout = time
......
......@@ -21,6 +21,7 @@ import (
"github.com/apache/dubbo-go/common"
)
// DynamicConfigurationFactory ...
type DynamicConfigurationFactory interface {
GetDynamicConfiguration(*common.URL) (DynamicConfiguration, error)
}
......@@ -32,6 +32,7 @@ import (
"github.com/apache/dubbo-go/remoting"
)
// MockDynamicConfigurationFactory ...
type MockDynamicConfigurationFactory struct {
Content string
}
......@@ -41,6 +42,7 @@ var (
dynamicConfiguration *MockDynamicConfiguration
)
// GetDynamicConfiguration ...
func (f *MockDynamicConfigurationFactory) GetDynamicConfiguration(url *common.URL) (DynamicConfiguration, error) {
var err error
once.Do(func() {
......@@ -79,19 +81,23 @@ func (f *MockDynamicConfigurationFactory) GetDynamicConfiguration(url *common.UR
}
// MockDynamicConfiguration ...
type MockDynamicConfiguration struct {
parser parser.ConfigurationParser
content string
listener map[string]ConfigurationListener
}
// AddListener ...
func (c *MockDynamicConfiguration) AddListener(key string, listener ConfigurationListener, opions ...Option) {
c.listener[key] = listener
}
// RemoveListener ...
func (c *MockDynamicConfiguration) RemoveListener(key string, listener ConfigurationListener, opions ...Option) {
}
// GetConfig ...
func (c *MockDynamicConfiguration) GetConfig(key string, opts ...Option) (string, error) {
return c.content, nil
......@@ -102,12 +108,17 @@ func (c *MockDynamicConfiguration) GetConfigs(key string, opts ...Option) (strin
return c.GetConfig(key, opts...)
}
// Parser ...
func (c *MockDynamicConfiguration) Parser() parser.ConfigurationParser {
return c.parser
}
// SetParser ...
func (c *MockDynamicConfiguration) SetParser(p parser.ConfigurationParser) {
c.parser = p
}
// GetProperties ...
func (c *MockDynamicConfiguration) GetProperties(key string, opts ...Option) (string, error) {
return c.content, nil
}
......@@ -117,10 +128,12 @@ func (c *MockDynamicConfiguration) GetInternalProperty(key string, opts ...Optio
return c.GetProperties(key, opts...)
}
// GetRule ...
func (c *MockDynamicConfiguration) GetRule(key string, opts ...Option) (string, error) {
return c.GetProperties(key, opts...)
}
// MockServiceConfigEvent ...
func (c *MockDynamicConfiguration) MockServiceConfigEvent() {
config := &parser.ConfiguratorConfig{
ConfigVersion: "2.7.1",
......@@ -142,6 +155,7 @@ func (c *MockDynamicConfiguration) MockServiceConfigEvent() {
c.listener[key].Process(&ConfigChangeEvent{Key: key, Value: string(value), ConfigType: remoting.EventTypeAdd})
}
// MockApplicationConfigEvent ...
func (c *MockDynamicConfiguration) MockApplicationConfigEvent() {
config := &parser.ConfiguratorConfig{
ConfigVersion: "2.7.1",
......
......@@ -40,6 +40,7 @@ const (
GeneralType = "general"
)
// ConfigurationParser ...
type ConfigurationParser interface {
Parse(string) (map[string]string, error)
ParseToUrls(content string) ([]*common.URL, error)
......@@ -48,6 +49,7 @@ type ConfigurationParser interface {
//for support properties file in config center
type DefaultConfigurationParser struct{}
// ConfiguratorConfig ...
type ConfiguratorConfig struct {
ConfigVersion string `yaml:"configVersion"`
Scope string `yaml:"scope"`
......@@ -56,6 +58,7 @@ type ConfiguratorConfig struct {
Configs []ConfigItem `yaml:"configs"`
}
// ConfigItem ...
type ConfigItem struct {
Type string `yaml:"type"`
Enabled bool `yaml:"enabled"`
......@@ -67,6 +70,7 @@ type ConfigItem struct {
Side string `yaml:"side"`
}
// Parse ...
func (parser *DefaultConfigurationParser) Parse(content string) (map[string]string, error) {
properties, err := properties.LoadString(content)
if err != nil {
......@@ -76,6 +80,7 @@ func (parser *DefaultConfigurationParser) Parse(content string) (map[string]stri
return properties.Map(), nil
}
// ParseToUrls ...
func (parser *DefaultConfigurationParser) ParseToUrls(content string) ([]*common.URL, error) {
config := ConfiguratorConfig{}
if err := yaml.Unmarshal([]byte(content), &config); err != nil {
......
......@@ -27,25 +27,30 @@ import (
"github.com/apache/dubbo-go/remoting"
)
// CacheListener ...
type CacheListener struct {
keyListeners sync.Map
rootPath string
}
// NewCacheListener ...
func NewCacheListener(rootPath string) *CacheListener {
return &CacheListener{rootPath: rootPath}
}
// AddListener ...
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
// make a map[your type]struct{} like set in java
listeners, loaded := l.keyListeners.LoadOrStore(key, map[config_center.ConfigurationListener]struct{}{listener: struct{}{}})
listeners, loaded := l.keyListeners.LoadOrStore(key, map[config_center.ConfigurationListener]struct{}{listener: {}})
if loaded {
listeners.(map[config_center.ConfigurationListener]struct{})[listener] = struct{}{}
l.keyListeners.Store(key, listeners)
}
}
// RemoveListener ...
func (l *CacheListener) RemoveListener(key string, listener config_center.ConfigurationListener) {
listeners, loaded := l.keyListeners.Load(key)
if loaded {
......@@ -53,6 +58,7 @@ func (l *CacheListener) RemoveListener(key string, listener config_center.Config
}
}
// DataChange ...
func (l *CacheListener) DataChange(event remoting.Event) bool {
if event.Content == "" {
//meanings new node
......
......@@ -67,6 +67,7 @@ type AccessLogFilter struct {
logChan chan AccessLogData
}
// Invoke ...
func (ef *AccessLogFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
accessLog := invoker.GetUrl().GetParam(constant.ACCESS_LOG_KEY, "")
if len(accessLog) > 0 {
......@@ -120,6 +121,7 @@ func (ef *AccessLogFilter) buildAccessLogData(invoker protocol.Invoker, invocati
return dataMap
}
// OnResponse ...
func (ef *AccessLogFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
......@@ -173,6 +175,7 @@ func isDefault(accessLog string) bool {
return strings.EqualFold("true", accessLog) || strings.EqualFold("default", accessLog)
}
// GetAccessLogFilter ...
func GetAccessLogFilter() filter.Filter {
accessLogFilter := &AccessLogFilter{logChan: make(chan AccessLogData, LogMaxBuffer)}
go func() {
......@@ -183,6 +186,7 @@ func GetAccessLogFilter() filter.Filter {
return accessLogFilter
}
// AccessLogData ...
type AccessLogData struct {
accessLog string
data map[string]string
......
......@@ -39,19 +39,20 @@ func init() {
extension.SetFilter(active, GetActiveFilter)
}
// ActiveFilter ...
type ActiveFilter struct {
}
// Invoke ...
func (ef *ActiveFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
logger.Infof("invoking active filter. %v,%v", invocation.MethodName(), len(invocation.Arguments()))
invocation.(*invocation2.RPCInvocation).SetAttachments(dubboInvokeStartTime, strconv.FormatInt(protocol.CurrentTimeMillis(), 10))
protocol.BeginCount(invoker.GetUrl(), invocation.MethodName())
return invoker.Invoke(ctx, invocation)
}
// OnResponse ...
func (ef *ActiveFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
startTime, err := strconv.ParseInt(invocation.(*invocation2.RPCInvocation).AttachmentsByKey(dubboInvokeStartTime, "0"), 10, 64)
if err != nil {
result.SetError(err)
......@@ -63,6 +64,7 @@ func (ef *ActiveFilter) OnResponse(ctx context.Context, result protocol.Result,
return result
}
// GetActiveFilter ...
func GetActiveFilter() filter.Filter {
return &ActiveFilter{}
}
......@@ -41,6 +41,7 @@ func init() {
// Echo func(ctx context.Context, arg interface{}, rsp *Xxx) error
type EchoFilter struct{}
// Invoke ...
func (ef *EchoFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
logger.Infof("invoking echo filter.")
logger.Debugf("%v,%v", invocation.MethodName(), len(invocation.Arguments()))
......@@ -54,10 +55,12 @@ func (ef *EchoFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invo
return invoker.Invoke(ctx, invocation)
}
// OnResponse ...
func (ef *EchoFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
// GetFilter ...
func GetFilter() filter.Filter {
return &EchoFilter{}
}
......@@ -72,10 +72,12 @@ type ExecuteLimitFilter struct {
executeState *concurrent.Map
}
// ExecuteState ...
type ExecuteState struct {
concurrentCount int64
}
// Invoke ...
func (ef *ExecuteLimitFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
methodConfigPrefix := "methods." + invocation.MethodName() + "."
url := invoker.GetUrl()
......@@ -117,6 +119,7 @@ func (ef *ExecuteLimitFilter) Invoke(ctx context.Context, invoker protocol.Invok
return invoker.Invoke(ctx, invocation)
}
// OnResponse ...
func (ef *ExecuteLimitFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
......@@ -132,6 +135,7 @@ func (state *ExecuteState) decrease() {
var executeLimitOnce sync.Once
var executeLimitFilter *ExecuteLimitFilter
// GetExecuteLimitFilter ...
func GetExecuteLimitFilter() filter.Filter {
executeLimitOnce.Do(func() {
executeLimitFilter = &ExecuteLimitFilter{
......
......@@ -43,8 +43,10 @@ func init() {
// when do a generic invoke, struct need to be map
// GenericFilter ...
type GenericFilter struct{}
// Invoke ...
func (ef *GenericFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
if invocation.MethodName() == constant.GENERIC && len(invocation.Arguments()) == 3 {
oldArguments := invocation.Arguments()
......@@ -67,10 +69,12 @@ func (ef *GenericFilter) Invoke(ctx context.Context, invoker protocol.Invoker, i
return invoker.Invoke(ctx, invocation)
}
// OnResponse ...
func (ef *GenericFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
// GetGenericFilter ...
func GetGenericFilter() filter.Filter {
return &GenericFilter{}
}
......
......@@ -48,8 +48,10 @@ func init() {
extension.SetFilter(GENERIC_SERVICE, GetGenericServiceFilter)
}
// GenericServiceFilter ...
type GenericServiceFilter struct{}
// Invoke ...
func (ef *GenericServiceFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
logger.Infof("invoking generic service filter.")
logger.Debugf("generic service filter methodName:%v,args:%v", invocation.MethodName(), len(invocation.Arguments()))
......@@ -111,6 +113,7 @@ func (ef *GenericServiceFilter) Invoke(ctx context.Context, invoker protocol.Inv
return invoker.Invoke(ctx, newInvocation)
}
// OnResponse ...
func (ef *GenericServiceFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
if invocation.MethodName() == constant.GENERIC && len(invocation.Arguments()) == 3 && result.Result() != nil {
v := reflect.ValueOf(result.Result())
......@@ -122,6 +125,7 @@ func (ef *GenericServiceFilter) OnResponse(ctx context.Context, result protocol.
return result
}
// GetGenericServiceFilter ...
func GetGenericServiceFilter() filter.Filter {
return &GenericServiceFilter{}
}
......@@ -58,6 +58,7 @@ func init() {
extension.SetFilter(HYSTRIX_PROVIDER, GetHystrixFilterProvider)
}
// HystrixFilterError ...
type HystrixFilterError struct {
err error
failByHystrix bool
......@@ -67,9 +68,12 @@ func (hfError *HystrixFilterError) Error() string {
return hfError.err.Error()
}
// FailByHystrix ...
func (hfError *HystrixFilterError) FailByHystrix() bool {
return hfError.failByHystrix
}
// NewHystrixFilterError ...
func NewHystrixFilterError(err error, failByHystrix bool) error {
return &HystrixFilterError{
err: err,
......@@ -77,14 +81,15 @@ func NewHystrixFilterError(err error, failByHystrix bool) error {
}
}
// HystrixFilter ...
type HystrixFilter struct {
COrP bool //true for consumer
res map[string][]*regexp.Regexp
ifNewMap sync.Map
}
// Invoke ...
func (hf *HystrixFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
cmdName := fmt.Sprintf("%s&method=%s", invoker.GetUrl().Key(), invocation.MethodName())
// Do the configuration if the circuit breaker is created for the first time
......@@ -145,9 +150,12 @@ func (hf *HystrixFilter) Invoke(ctx context.Context, invoker protocol.Invoker, i
return result
}
// OnResponse ...
func (hf *HystrixFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
// GetHystrixFilterConsumer ...
func GetHystrixFilterConsumer() filter.Filter {
//When first called, load the config in
consumerConfigOnce.Do(func() {
......@@ -158,6 +166,7 @@ func GetHystrixFilterConsumer() filter.Filter {
return &HystrixFilter{COrP: true}
}
// GetHystrixFilterProvider ...
func GetHystrixFilterProvider() filter.Filter {
providerConfigOnce.Do(func() {
if err := initHystrixConfigProvider(); err != nil {
......@@ -216,6 +225,7 @@ func initHystrixConfigConsumer() error {
}
return nil
}
func initHystrixConfigProvider() error {
if config.GetProviderConfig().FilterConf == nil {
return perrors.Errorf("no config for hystrix")
......@@ -242,6 +252,7 @@ func initHystrixConfigProvider() error {
// return initHystrixConfig()
//}
// CommandConfigWithError ...
type CommandConfigWithError struct {
Timeout int `yaml:"timeout"`
MaxConcurrentRequests int `yaml:"max_concurrent_requests"`
......@@ -259,11 +270,14 @@ type CommandConfigWithError struct {
//- ErrorPercentThreshold: it causes circuits to open once the rolling measure of errors exceeds this percent of requests
//See hystrix doc
// HystrixFilterConfig ...
type HystrixFilterConfig struct {
Configs map[string]*CommandConfigWithError
Default string
Services map[string]ServiceHystrixConfig
}
// ServiceHystrixConfig ...
type ServiceHystrixConfig struct {
ServiceConfig string `yaml:"service_config"`
Methods map[string]string
......
......@@ -41,8 +41,10 @@ func init() {
extension.SetFilter(TOKEN, GetTokenFilter)
}
// TokenFilter ...
type TokenFilter struct{}
// Invoke ...
func (tf *TokenFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
invokerTkn := invoker.GetUrl().GetParam(constant.TOKEN_KEY, "")
if len(invokerTkn) > 0 {
......@@ -58,10 +60,12 @@ func (tf *TokenFilter) Invoke(ctx context.Context, invoker protocol.Invoker, inv
return invoker.Invoke(ctx, invocation)
}
// OnResponse ...
func (tf *TokenFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
// GetTokenFilter ...
func GetTokenFilter() filter.Filter {
return &TokenFilter{}
}
......@@ -63,6 +63,7 @@ type FixedWindowTpsLimitStrategyImpl struct {
timestamp int64
}
// IsAllowable ...
func (impl *FixedWindowTpsLimitStrategyImpl) IsAllowable() bool {
current := time.Now().UnixNano()
......
......@@ -53,6 +53,7 @@ type SlidingWindowTpsLimitStrategyImpl struct {
queue *list.List
}
// IsAllowable ...
func (impl *SlidingWindowTpsLimitStrategyImpl) IsAllowable() bool {
impl.mutex.Lock()
defer impl.mutex.Unlock()
......
......@@ -52,6 +52,7 @@ type ThreadSafeFixedWindowTpsLimitStrategyImpl struct {
fixedWindow *FixedWindowTpsLimitStrategyImpl
}
// IsAllowable ...
func (impl *ThreadSafeFixedWindowTpsLimitStrategyImpl) IsAllowable() bool {
impl.mutex.Lock()
defer impl.mutex.Unlock()
......
......@@ -111,6 +111,7 @@ type MethodServiceTpsLimiterImpl struct {
tpsState *concurrent.Map
}
// IsAllowable ...
func (limiter MethodServiceTpsLimiterImpl) IsAllowable(url common.URL, invocation protocol.Invocation) bool {
methodConfigPrefix := "methods." + invocation.MethodName() + "."
......@@ -178,6 +179,7 @@ func getLimitConfig(methodLevelConfig string,
var methodServiceTpsLimiterInstance *MethodServiceTpsLimiterImpl
var methodServiceTpsLimiterOnce sync.Once
// GetMethodServiceTpsLimiter ...
func GetMethodServiceTpsLimiter() filter.TpsLimiter {
methodServiceTpsLimiterOnce.Do(func() {
methodServiceTpsLimiterInstance = &MethodServiceTpsLimiterImpl{
......
......@@ -54,6 +54,7 @@ func init() {
type TpsLimitFilter struct {
}
// Invoke ...
func (t TpsLimitFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
url := invoker.GetUrl()
tpsLimiter := url.GetParam(constant.TPS_LIMITER_KEY, "")
......@@ -69,10 +70,12 @@ func (t TpsLimitFilter) Invoke(ctx context.Context, invoker protocol.Invoker, in
return invoker.Invoke(ctx, invocation)
}
// OnResponse ...
func (t TpsLimitFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
// GetTpsLimitFilter ...
func GetTpsLimitFilter() filter.Filter {
return &TpsLimitFilter{}
}
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