common

package
v3.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 26 Imported by: 119

Documentation

Index

Constants

View Source
const (
	CONSUMER = iota
	CONFIGURATOR
	ROUTER
	PROVIDER
	PROTOCOL = "protocol"
)

dubbo role type constant

View Source
const (
	METHOD_MAPPER = "MethodMapper"
)

Variables

View Source
var (
	DubboNodes = [...]string{"consumers", "configurators", "routers", "providers"} // Dubbo service node
	DubboRole  = [...]string{"consumer", "", "routers", "provider"}                // Dubbo service role

)
View Source
var (

	// ServiceMap store description of service.
	ServiceMap = &serviceMap{
		serviceMap:   make(map[string]map[string]*Service),
		interfaceMap: make(map[string][]*Service),
	}
)

Functions

func GetLocalHostName added in v3.1.1

func GetLocalHostName() string

func GetLocalIp

func GetLocalIp() string

func GetReference

func GetReference(service RPCService) string

GetReference return the reference id of the service. If the service implemented the ReferencedRPCService interface, it will call the Reference method. If not, it will return the struct name as the reference id.

func GetSubscribeName added in v3.0.2

func GetSubscribeName(url *URL) string

func HandleRegisterIPAndPort added in v3.0.4

func HandleRegisterIPAndPort(url *URL)

func IsAnyCondition added in v3.1.0

func IsAnyCondition(intf, group, version string, serviceURL *URL) bool

IsAnyCondition judges if is any condition

func IsEquals

func IsEquals(left *URL, right *URL, excludes ...string) bool

IsEquals compares if two URLs equals with each other. Excludes are all parameter keys which should ignored.

func IsMatchGlobPattern added in v3.1.1

func IsMatchGlobPattern(pattern, value string) bool

func MatchKey

func MatchKey(serviceKey string, protocol string) string

func ParseServiceKey added in v3.1.0

func ParseServiceKey(serviceKey string) (string, string, string)

ParseServiceKey gets interface, group and version from service key

func ServiceKey

func ServiceKey(intf string, group string, version string) string

func SetCompareURLEqualFunc

func SetCompareURLEqualFunc(f CompareURLEqualFunc)

Types

type AddressMatch added in v3.1.1

type AddressMatch struct {
	Wildcard string `yaml:"wildcard" json:"wildcard,omitempty" property:"wildcard"`
	Cird     string `yaml:"cird" json:"cird,omitempty" property:"cird"`
	Exact    string `yaml:"exact" json:"exact,omitempty" property:"exact"`
}

func (*AddressMatch) IsMatch added in v3.1.1

func (p *AddressMatch) IsMatch(value string) bool

type AsyncCallback

type AsyncCallback func(response CallbackResponse)

AsyncCallback async callback method

type AsyncCallbackService

type AsyncCallbackService interface {
	CallBack(response CallbackResponse)
}

AsyncCallbackService callback interface for async

type CallbackResponse

type CallbackResponse interface{}

CallbackResponse for different protocol

type CompareURLEqualFunc

type CompareURLEqualFunc func(l *URL, r *URL, excludeParam ...string) bool

func GetCompareURLEqualFunc

func GetCompareURLEqualFunc() CompareURLEqualFunc

type ListStringMatch added in v3.1.1

type ListStringMatch struct {
	Oneof []StringMatch `yaml:"oneof" json:"oneof,omitempty" property:"oneof"`
}

func (*ListStringMatch) IsMatch added in v3.1.1

func (p *ListStringMatch) IsMatch(value string) bool

type MetadataInfo

type MetadataInfo struct {
	Reported bool                    `json:"-"`
	App      string                  `json:"app,omitempty"`
	Revision string                  `json:"revision,omitempty"`
	Services map[string]*ServiceInfo `json:"services,omitempty"`
}

MetadataInfo the metadata information of instance

func NewMetadataInfWithApp

func NewMetadataInfWithApp(app string) *MetadataInfo

nolint

func NewMetadataInfo

func NewMetadataInfo(app string, revision string, services map[string]*ServiceInfo) *MetadataInfo

nolint

func (*MetadataInfo) AddService

func (mi *MetadataInfo) AddService(service *ServiceInfo)

nolint

func (*MetadataInfo) CalAndGetRevision

func (mi *MetadataInfo) CalAndGetRevision() string

CalAndGetRevision is different from Dubbo because golang doesn't support overload so that we should use interface + method name as identifier and ignore the method params in my opinion, it's enough because Dubbo actually ignore the URL params. please refer org.apache.dubbo.common.URL#toParameterString(java.lang.String...)

func (*MetadataInfo) HasReported

func (mi *MetadataInfo) HasReported() bool

nolint

func (*MetadataInfo) JavaClassName

func (mi *MetadataInfo) JavaClassName() string

nolint

func (*MetadataInfo) MarkReported

func (mi *MetadataInfo) MarkReported()

nolint

func (*MetadataInfo) RemoveService

func (mi *MetadataInfo) RemoveService(service *ServiceInfo)

nolint

type MethodType

type MethodType struct {
	// contains filtered or unexported fields
}

MethodType is description of service method.

func (*MethodType) ArgsType

func (m *MethodType) ArgsType() []reflect.Type

ArgsType gets @m.argsType.

func (*MethodType) CtxType

func (m *MethodType) CtxType() reflect.Type

CtxType gets @m.ctxType.

func (*MethodType) Method

func (m *MethodType) Method() reflect.Method

Method gets @m.method.

func (*MethodType) ReplyType

func (m *MethodType) ReplyType() reflect.Type

ReplyType gets @m.replyType.

func (*MethodType) SuiteContext

func (m *MethodType) SuiteContext(ctx context.Context) reflect.Value

SuiteContext transfers @ctx to reflect.Value type or get it from @m.ctxType.

type Node

type Node interface {
	GetURL() *URL
	IsAvailable() bool
	Destroy()
}

Node use for process dubbo node

type Option

type Option func(*URL)

Option accepts URL Option will define a function of handling URL

func WithInterface added in v3.1.0

func WithInterface(v string) Option

WithInterface sets interface param for URL

func WithIp

func WithIp(ip string) Option

WithIp sets ip for URL

func WithLocation

func WithLocation(location string) Option

WithLocation sets location for URL

func WithMethods

func WithMethods(methods []string) Option

WithMethods sets methods for URL

func WithParams

func WithParams(params url.Values) Option

WithParams deep copy the params in the argument into params of the target URL

func WithParamsValue

func WithParamsValue(key, val string) Option

WithParamsValue sets params field for URL

func WithPassword

func WithPassword(pwd string) Option

WithPassword sets password for URL

func WithPath

func WithPath(path string) Option

WithPath sets path for URL

func WithPort

func WithPort(port string) Option

WithPort sets port for URL

func WithProtocol

func WithProtocol(proto string) Option

WithProtocol sets protocol for URL

func WithToken

func WithToken(token string) Option

WithToken sets token for URL

func WithUsername

func WithUsername(username string) Option

WithUsername sets username for URL

type ParamMatch added in v3.1.1

type ParamMatch struct {
	Key   string      `yaml:"key" json:"key,omitempty" property:"key"`
	Value StringMatch `yaml:"value" json:"value,omitempty" property:"value"`
}

func (*ParamMatch) IsMatch added in v3.1.1

func (p *ParamMatch) IsMatch(url *URL) bool

type RPCService

type RPCService = interface{}

RPCService the type alias of interface{}

type ReferencedRPCService

type ReferencedRPCService interface {
	Reference() string
}

ReferencedRPCService is the rpc service interface which wraps base Reference method.

Reference method refers rpc service id or reference id.

type RoleType

type RoleType int

nolint

func (RoleType) Role

func (t RoleType) Role() string

Role returns role by @RoleType

func (RoleType) String

func (t RoleType) String() string

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is description of service

func (*Service) Method

func (s *Service) Method() map[string]*MethodType

Method gets @s.methods.

func (*Service) Name

func (s *Service) Name() string

Name will return service name

func (*Service) Rcvr

func (s *Service) Rcvr() reflect.Value

Rcvr gets @s.rcvr.

func (*Service) RcvrType

func (s *Service) RcvrType() reflect.Type

RcvrType gets @s.rcvrType.

type ServiceInfo

type ServiceInfo struct {
	Name     string            `json:"name,omitempty"`
	Group    string            `json:"group,omitempty"`
	Version  string            `json:"version,omitempty"`
	Protocol string            `json:"protocol,omitempty"`
	Path     string            `json:"path,omitempty"`
	Params   map[string]string `json:"params,omitempty"`

	ServiceKey string `json:"-"`
	MatchKey   string `json:"-"`
	URL        *URL   `json:"-"`
}

ServiceInfo the information of service

func NewServiceInfo

func NewServiceInfo(name, group, version, protocol, path string, params map[string]string) *ServiceInfo

nolint

func NewServiceInfoWithURL

func NewServiceInfoWithURL(url *URL) *ServiceInfo

nolint

func (*ServiceInfo) GetMatchKey

func (si *ServiceInfo) GetMatchKey() string

nolint

func (*ServiceInfo) GetMethods

func (si *ServiceInfo) GetMethods() []string

nolint

func (*ServiceInfo) GetParams

func (si *ServiceInfo) GetParams() url.Values

nolint

func (*ServiceInfo) GetServiceKey

func (si *ServiceInfo) GetServiceKey() string

nolint

func (*ServiceInfo) JavaClassName

func (si *ServiceInfo) JavaClassName() string

nolint

type StringMatch added in v3.1.1

type StringMatch struct {
	Exact    string `yaml:"exact" json:"exact,omitempty" property:"exact"`
	Prefix   string `yaml:"prefix" json:"prefix,omitempty" property:"prefix"`
	Regex    string `yaml:"regex" json:"regex,omitempty" property:"regex"`
	Noempty  string `yaml:"noempty" json:"noempty,omitempty" property:"noempty"`
	Empty    string `yaml:"empty" json:"empty,omitempty" property:"empty"`
	Wildcard string `yaml:"wildcard" json:"wildcard,omitempty" property:"wildcard"`
}

func (*StringMatch) IsMatch added in v3.1.1

func (p *StringMatch) IsMatch(value string) bool

type TriplePBService

type TriplePBService interface {
	XXX_InterfaceName() string
}

TriplePBService is the type alias of interface{}

type URL

type URL struct {
	Path     string // like  /com.ikurento.dubbo.UserProvider
	Username string
	Password string
	Methods  []string
	// special for registry
	SubURL *URL
	// contains filtered or unexported fields
}

URL thread-safe. but this URL should not be copied. we fail to define this struct to be immutable object. but, those method which will update the URL, including SetParam, SetParams are only allowed to be invoked in creating URL instance Please keep in mind that this struct is immutable after it has been created and initialized.

func MergeURL

func MergeURL(serviceURL *URL, referenceURL *URL) *URL

MergeURL will merge those two URL the result is based on serviceURL, and the key which si only contained in referenceURL will be added into result. for example, if serviceURL contains params (a1->v1, b1->v2) and referenceURL contains params(a2->v3, b1 -> v4) the params of result will be (a1->v1, b1->v2, a2->v3). You should notice that the value of b1 is v2, not v4 except constant.LoadbalanceKey, constant.ClusterKey, constant.RetriesKey, constant.TimeoutKey. due to URL is not thread-safe, so this method is not thread-safe

func NewURL

func NewURL(urlString string, opts ...Option) (*URL, error)

NewURL will create a new URL the urlString should not be empty

func NewURLWithOptions

func NewURLWithOptions(opts ...Option) *URL

NewURLWithOptions will create a new URL with options

func (*URL) AddAttribute added in v3.1.1

func (c *URL) AddAttribute(key string, value interface{})

func (*URL) AddParam

func (c *URL) AddParam(key string, value string)

AddParam will add the key-value pair

func (*URL) AddParamAvoidNil

func (c *URL) AddParamAvoidNil(key string, value string)

AddParamAvoidNil will add key-value pair

func (*URL) Address added in v3.1.0

func (c *URL) Address() string

Address with format "ip:port"

func (*URL) Clone

func (c *URL) Clone() *URL

Clone will copy the URL

func (*URL) CloneExceptParams

func (c *URL) CloneExceptParams(excludeParams *gxset.HashSet) *URL

func (*URL) CloneWithParams

func (c *URL) CloneWithParams(reserveParams []string) *URL

CloneWithParams Copy URL based on the reserved parameter's keys.

func (*URL) ColonSeparatedKey

func (c *URL) ColonSeparatedKey() string

ColonSeparatedKey The format is "{interface}:[version]:[group]"

func (*URL) Compare

func (c *URL) Compare(comp cm.Comparator) int

func (*URL) DelParam

func (c *URL) DelParam(key string)

DelParam will delete the given key from the URL

func (*URL) EncodedServiceKey

func (c *URL) EncodedServiceKey() string

EncodedServiceKey encode the service key

func (*URL) GetAttribute added in v3.1.1

func (c *URL) GetAttribute(key string) interface{}

func (*URL) GetCacheInvokerMapKey

func (c *URL) GetCacheInvokerMapKey() string

GetCacheInvokerMapKey get directory cacheInvokerMap key

func (*URL) GetMethodParam

func (c *URL) GetMethodParam(method string, key string, d string) string

GetMethodParam gets method param

func (*URL) GetMethodParamBool

func (c *URL) GetMethodParamBool(method string, key string, d bool) bool

GetMethodParamBool judge whether @method param exists or not

func (*URL) GetMethodParamInt

func (c *URL) GetMethodParamInt(method string, key string, d int64) int64

GetMethodParamInt gets int method param

func (*URL) GetMethodParamInt64

func (c *URL) GetMethodParamInt64(method string, key string, d int64) int64

GetMethodParamInt64 gets int64 method param

func (*URL) GetMethodParamIntValue

func (c *URL) GetMethodParamIntValue(method string, key string, d int) int

GetMethodParamIntValue gets int method param

func (*URL) GetNonDefaultParam added in v3.1.0

func (c *URL) GetNonDefaultParam(s string) (string, bool)

GetNonDefaultParam gets value by key, return nil,false if no value found mapping to the key

func (*URL) GetParam

func (c *URL) GetParam(s string, d string) string

GetParam gets value by key

func (*URL) GetParamAndDecoded

func (c *URL) GetParamAndDecoded(key string) (string, error)

GetParamAndDecoded gets values and decode

func (*URL) GetParamBool

func (c *URL) GetParamBool(key string, d bool) bool

GetParamBool judge whether @key exists or not

func (*URL) GetParamByIntValue

func (c *URL) GetParamByIntValue(key string, d int) int

GetParamByIntValue gets int value by @key

func (*URL) GetParamDuration

func (c *URL) GetParamDuration(s string, d string) time.Duration

GetParamDuration get duration if param is invalid or missing will return 3s

func (*URL) GetParamInt

func (c *URL) GetParamInt(key string, d int64) int64

GetParamInt gets int64 value by @key

func (*URL) GetParamInt32

func (c *URL) GetParamInt32(key string, d int32) int32

GetParamInt32 gets int32 value by @key

func (*URL) GetParams

func (c *URL) GetParams() url.Values

GetParams gets values

func (*URL) GetRawParam

func (c *URL) GetRawParam(key string) string

GetRawParam gets raw param

func (*URL) Group

func (c *URL) Group() string

Group get group

func (*URL) Interface added in v3.0.4

func (c *URL) Interface() string

Interface get interface

func (*URL) JavaClassName

func (c *URL) JavaClassName() string

JavaClassName POJO for URL

func (*URL) Key

func (c *URL) Key() string

Key gets key

func (*URL) RangeParams

func (c *URL) RangeParams(f func(key, value string) bool)

RangeParams will iterate the params

func (*URL) ReplaceParams

func (c *URL) ReplaceParams(param url.Values)

ReplaceParams will replace the URL.params usually it should only be invoked when you want to modify an URL, such as MergeURL

func (*URL) Service

func (c *URL) Service() string

Service gets service

func (*URL) ServiceKey

func (c *URL) ServiceKey() string

ServiceKey gets a unique key of a service.

func (*URL) SetParam

func (c *URL) SetParam(key string, value string)

SetParam will put the key-value pair into URL usually it should only be invoked when you want to initialized an URL

func (*URL) SetParams

func (c *URL) SetParams(m url.Values)

SetParams will put all key-value pair into URL. 1. if there already has same key, the value will be override 2. it's not thread safe 3. think twice when you want to invoke this method

func (*URL) String

func (c *URL) String() string

func (*URL) ToMap

func (c *URL) ToMap() map[string]string

ToMap transfer URL to Map

func (*URL) URLEqual

func (c *URL) URLEqual(url *URL) bool

URLEqual judge @URL and @c is equal or not.

func (*URL) Version

func (c *URL) Version() string

Version get group

type URLSlice

type URLSlice []*URL

URLSlice will be used to sort URL instance Instances will be order by URL.String()

func (URLSlice) Len

func (s URLSlice) Len() int

nolint

func (URLSlice) Less

func (s URLSlice) Less(i, j int) bool

nolint

func (URLSlice) Swap

func (s URLSlice) Swap(i, j int)

nolint

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL