Skip to content

Commit

Permalink
Merge pull request #579 from watermelo/featue/addCommentForConfig
Browse files Browse the repository at this point in the history
Feat: add comments for config
  • Loading branch information
Patrick0308 committed Jun 3, 2020
2 parents 4af26b9 + bada632 commit 962025b
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 78 deletions.
18 changes: 4 additions & 14 deletions config/application_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"github.com/apache/dubbo-go/common/constant"
)

// ApplicationConfig ...
// ApplicationConfig is a configuration for current application, whether the application is a provider or a consumer
type ApplicationConfig struct {
Organization string `yaml:"organization" json:"organization,omitempty" property:"organization"`
Organization string `yaml:"organization" json:"organization,omitempty" property:"organization"`
Name string `yaml:"name" json:"name,omitempty" property:"name"`
Module string `yaml:"module" json:"module,omitempty" property:"module"`
Version string `yaml:"version" json:"version,omitempty" property:"version"`
Expand All @@ -36,22 +36,12 @@ type ApplicationConfig struct {
MetadataType string `default:"local" yaml:"metadataType" json:"metadataType,omitempty" property:"metadataType"` //field for metadata report
}

// Prefix ...
// nolint
func (*ApplicationConfig) Prefix() string {
return constant.DUBBO + ".application."
}

// Id ...
func (c *ApplicationConfig) Id() string {
return ""
}

// SetId ...
func (c *ApplicationConfig) SetId(id string) {

}

// UnmarshalYAML ...
// UnmarshalYAML unmarshals the ApplicationConfig by @unmarshal function
func (c *ApplicationConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := defaults.Set(c); err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions config/base_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func (c *BaseConfig) startConfigCenter() error {
}

func (c *BaseConfig) prepareEnvironment() error {

factory := extension.GetConfigCenterFactory(c.ConfigCenterConfig.Protocol)
dynamicConfig, err := factory.GetDynamicConfiguration(c.configCenterUrl)
config.GetEnvInstance().SetDynamicConfiguration(dynamicConfig)
Expand Down Expand Up @@ -323,7 +322,7 @@ func (c *BaseConfig) freshInternalConfig(config *config.InmemoryConfiguration) {
setFieldValue(val, reflect.Value{}, config)
}

// SetFatherConfig ...
// SetFatherConfig sets father config by @fatherConfig
func (c *BaseConfig) SetFatherConfig(fatherConfig interface{}) {
c.fatherConfig = fatherConfig
}
Expand Down
12 changes: 9 additions & 3 deletions config/config_center_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ import (
"github.com/apache/dubbo-go/common/constant"
)

// ConfigCenterConfig ...
// ConfigCenterConfig is configuration for config center
//
// ConfigCenter also introduced concepts of namespace and group to better manage Key-Value pairs by group,
// those configs are already built-in in many professional third-party configuration centers.
// In most cases, namespace is used to isolate different tenants, while group is used to divide the key set from one tenant into groups.
//
// ConfigCenter has currently supported Zookeeper, Nacos, Etcd, Consul, Apollo
type ConfigCenterConfig struct {
context context.Context
Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"`
Expand All @@ -48,7 +54,7 @@ type ConfigCenterConfig struct {
timeout time.Duration
}

// UnmarshalYAML ...
// UnmarshalYAML unmarshals the ConfigCenterConfig by @unmarshal function
func (c *ConfigCenterConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := defaults.Set(c); err != nil {
return err
Expand All @@ -60,7 +66,7 @@ func (c *ConfigCenterConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
return nil
}

// GetUrlMap ...
// GetUrlMap gets url map from ConfigCenterConfig
func (c *ConfigCenterConfig) GetUrlMap() url.Values {
urlMap := url.Values{}
urlMap.Set(constant.CONFIG_NAMESPACE_KEY, c.Namespace)
Expand Down
10 changes: 5 additions & 5 deletions config/consumer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
// consumerConfig
/////////////////////////

// ConsumerConfig ...
// ConsumerConfig is Consumer default configuration
type ConsumerConfig struct {
BaseConfig `yaml:",inline"`
Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"`
Expand All @@ -63,7 +63,7 @@ type ConsumerConfig struct {
ConfigType map[string]string `yaml:"config_type" json:"config_type,omitempty" property:"config_type"`
}

// UnmarshalYAML ...
// UnmarshalYAML unmarshals the ConsumerConfig by @unmarshal function
func (c *ConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := defaults.Set(c); err != nil {
return err
Expand All @@ -75,17 +75,17 @@ func (c *ConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
return nil
}

// Prefix ...
// nolint
func (*ConsumerConfig) Prefix() string {
return constant.ConsumerConfigPrefix
}

// SetConsumerConfig ...
// SetConsumerConfig sets consumerConfig by @c
func SetConsumerConfig(c ConsumerConfig) {
consumerConfig = &c
}

// ConsumerInit ...
// ConsumerInit loads config file to init consumer config
func ConsumerInit(confConFile string) error {
if confConFile == "" {
return perrors.Errorf("application configure(consumer) file name is nil")
Expand Down
6 changes: 3 additions & 3 deletions config/generic_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ package config

import "context"

// GenericService ...
// GenericService uses for generic invoke for service call
type GenericService struct {
Invoke func(ctx context.Context, req []interface{}) (interface{}, error) `dubbo:"$invoke"`
referenceStr string
}

// NewGenericService ...
// NewGenericService returns a GenericService instance
func NewGenericService(referenceStr string) *GenericService {
return &GenericService{referenceStr: referenceStr}
}

// Reference ...
// Reference gets referenceStr from GenericService
func (u *GenericService) Reference() string {
return u.referenceStr
}
14 changes: 5 additions & 9 deletions config/graceful_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import (
* We define them by using 'package build' feature https://golang.org/pkg/go/build/
*/

// GracefulShutdownInit ...
// nolint
func GracefulShutdownInit() {

signals := make(chan os.Signal, 1)
Expand Down Expand Up @@ -83,7 +83,7 @@ func GracefulShutdownInit() {
}()
}

// BeforeShutdown ...
// BeforeShutdown provides processing flow before shutdown
func BeforeShutdown() {

destroyAllRegistries()
Expand Down Expand Up @@ -126,10 +126,8 @@ func destroyConsumerProtocols(consumerProtocols *gxset.HashSet) {
}
}

/**
* destroy the provider's protocol.
* if the protocol is consumer's protocol too, we will keep it.
*/
// destroyProviderProtocols destroys the provider's protocol.
// if the protocol is consumer's protocol too, we will keep it
func destroyProviderProtocols(consumerProtocols *gxset.HashSet) {

logger.Info("Graceful shutdown --- Destroy provider's protocols. ")
Expand Down Expand Up @@ -215,9 +213,7 @@ func totalTimeout() time.Duration {
return timeout
}

/*
* we can not get the protocols from consumerConfig because some protocol don't have configuration, like jsonrpc.
*/
// we can not get the protocols from consumerConfig because some protocol don't have configuration, like jsonrpc.
func getConsumerProtocols() *gxset.HashSet {
result := gxset.NewSet()
if consumerConfig == nil || consumerConfig.References == nil {
Expand Down
8 changes: 4 additions & 4 deletions config/graceful_shutdown_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
defaultStepTimeout = 10 * time.Second
)

// ShutdownConfig ...
// ShutdownConfig is used as configuration for graceful shutdown
type ShutdownConfig struct {
/*
* Total timeout. Even though we don't release all resources,
Expand All @@ -58,12 +58,12 @@ type ShutdownConfig struct {
RequestsFinished bool
}

// Prefix ...
// nolint
func (config *ShutdownConfig) Prefix() string {
return constant.ShutdownConfigPrefix
}

// GetTimeout ...
// nolint
func (config *ShutdownConfig) GetTimeout() time.Duration {
result, err := time.ParseDuration(config.Timeout)
if err != nil {
Expand All @@ -74,7 +74,7 @@ func (config *ShutdownConfig) GetTimeout() time.Duration {
return result
}

// GetStepTimeout ...
// nolint
func (config *ShutdownConfig) GetStepTimeout() time.Duration {
result, err := time.ParseDuration(config.StepTimeout)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/graceful_shutdown_signal_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
)

var (
// ShutdownSignals ...
// ShutdownSignals receives shutdown signals to process
ShutdownSignals = []os.Signal{os.Interrupt, os.Kill, syscall.SIGKILL, syscall.SIGSTOP,
syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP,
syscall.SIGABRT, syscall.SIGSYS}

// DumpHeapShutdownSignals ...
// DumpHeapShutdownSignals receives shutdown signals to process
DumpHeapShutdownSignals = []os.Signal{syscall.SIGQUIT, syscall.SIGILL,
syscall.SIGTRAP, syscall.SIGABRT, syscall.SIGSYS}
)
4 changes: 2 additions & 2 deletions config/graceful_shutdown_signal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
)

var (
// ShutdownSignals ...
// ShutdownSignals receives shutdown signals to process
ShutdownSignals = []os.Signal{os.Interrupt, os.Kill, syscall.SIGKILL, syscall.SIGSTOP,
syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP,
syscall.SIGABRT, syscall.SIGSYS}

// DumpHeapShutdownSignals ...
// DumpHeapShutdownSignals receives shutdown signals to process
DumpHeapShutdownSignals = []os.Signal{syscall.SIGQUIT, syscall.SIGILL,
syscall.SIGTRAP, syscall.SIGABRT, syscall.SIGSYS}
)
4 changes: 2 additions & 2 deletions config/graceful_shutdown_signal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
)

var (
// ShutdownSignals ...
// ShutdownSignals receives shutdown signals to process
ShutdownSignals = []os.Signal{os.Interrupt, os.Kill, syscall.SIGKILL,
syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP,
syscall.SIGABRT}

// DumpHeapShutdownSignals ...
// DumpHeapShutdownSignals receives shutdown signals to process
DumpHeapShutdownSignals = []os.Signal{syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, syscall.SIGABRT}
)
2 changes: 1 addition & 1 deletion config/instance/metadata_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
once sync.Once
)

// GetMetadataReportInstance ...
// GetMetadataReportInstance gets metadata report instance by @url
func GetMetadataReportInstance(url *common.URL) metadata.MetadataReport {
once.Do(func() {
instance = extension.GetMetadataReportFactory(url.Protocol).CreateMetadataReport(url)
Expand Down
2 changes: 1 addition & 1 deletion config/interfaces/config_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package interfaces

import "bytes"

// ConfigReader
// ConfigReader is used to read config from consumer or provider
type ConfigReader interface {
ReadConsumerConfig(reader *bytes.Buffer) error
ReadProviderConfig(reader *bytes.Buffer) error
Expand Down
8 changes: 4 additions & 4 deletions config/metadata_report_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/apache/dubbo-go/config/instance"
)

// MethodConfig ...
// MethodConfig is method level configuration
type MetadataReportConfig struct {
Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"`
Address string `yaml:"address" json:"address,omitempty" property:"address"`
Expand All @@ -43,12 +43,12 @@ type MetadataReportConfig struct {
Group string `yaml:"group" json:"group,omitempty" property:"group"`
}

// Prefix ...
// nolint
func (c *MetadataReportConfig) Prefix() string {
return constant.MetadataReportPrefix
}

// UnmarshalYAML ...
// UnmarshalYAML unmarshal the MetadataReportConfig by @unmarshal function
func (c *MetadataReportConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := defaults.Set(c); err != nil {
return perrors.WithStack(err)
Expand All @@ -60,7 +60,7 @@ func (c *MetadataReportConfig) UnmarshalYAML(unmarshal func(interface{}) error)
return nil
}

// ToUrl ...
// nolint
func (c *MetadataReportConfig) ToUrl() (*common.URL, error) {
urlMap := make(url.Values)

Expand Down
4 changes: 2 additions & 2 deletions config/method_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type MethodConfig struct {
RequestTimeout string `yaml:"timeout" json:"timeout,omitempty" property:"timeout"`
}

// Prefix ...
// nolint
func (c *MethodConfig) Prefix() string {
if len(c.InterfaceId) != 0 {
return constant.DUBBO + "." + c.InterfaceName + "." + c.InterfaceId + "." + c.Name + "."
Expand All @@ -51,7 +51,7 @@ func (c *MethodConfig) Prefix() string {
return constant.DUBBO + "." + c.InterfaceName + "." + c.Name + "."
}

// UnmarshalYAML ...
// UnmarshalYAML unmarshals the MethodConfig by @unmarshal function
func (c *MethodConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := defaults.Set(c); err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions config/mock_rpcservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ import (
"context"
)

// MockService ...
// MockService mocks the rpc service for test
type MockService struct{}

// Reference ...
// Reference mocks the Reference method
func (*MockService) Reference() string {
return "MockService"
}

// GetUser ...
// GetUser mocks the GetUser method
func (*MockService) GetUser(ctx context.Context, itf []interface{}, str *struct{}) error {
return nil
}

// GetUser1 ...
// GetUser1 mocks the GetUser1 method
func (*MockService) GetUser1(ctx context.Context, itf []interface{}, str *struct{}) error {
return nil
}
4 changes: 2 additions & 2 deletions config/protocol_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (
"github.com/apache/dubbo-go/common/constant"
)

// ProtocolConfig ...
// ProtocolConfig is protocol configuration
type ProtocolConfig struct {
Name string `required:"true" yaml:"name" json:"name,omitempty" property:"name"`
Ip string `required:"true" yaml:"ip" json:"ip,omitempty" property:"ip"`
Port string `required:"true" yaml:"port" json:"port,omitempty" property:"port"`
}

// Prefix ...
// nolint
func (c *ProtocolConfig) Prefix() string {
return constant.ProtocolConfigPrefix
}
Expand Down
Loading

0 comments on commit 962025b

Please sign in to comment.