common

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: Apache-2.0 Imports: 22 Imported by: 37

Documentation

Index

Constants

View Source
const (
	// CONSUMER is consumer role
	CONSUMER = iota
	// CONFIGURATOR is configurator role
	CONFIGURATOR
	// ROUTER is router role
	ROUTER
	// PROVIDER is provider role
	PROVIDER
	PROTOCOL = "protocol"
)

/////////////////////////////// dubbo role type /////////////////////////////// role constant

View Source
const (
	METHOD_MAPPER = "MethodMapper"
)

for lowercase func

func MethodMapper() map[string][string] {
    return map[string][string]{}
}

Variables

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

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

Functions

func GetLocalIp added in v1.5.5

func GetLocalIp() string

func IsEquals added in v1.5.3

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 ServiceKey added in v1.5.3

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

func SetCompareURLEqualFunc added in v1.5.6

func SetCompareURLEqualFunc(f CompareURLEqualFunc)

Types

type AsyncCallback added in v1.3.0

type AsyncCallback func(response CallbackResponse)

AsyncCallback async callback method

type AsyncCallbackService added in v1.3.0

type AsyncCallbackService interface {
	// Callback: callback
	CallBack(response CallbackResponse)
}

AsyncCallbackService callback interface for async

type CallbackResponse added in v1.3.0

type CallbackResponse interface{}

CallbackResponse for different protocol

type CompareURLEqualFunc added in v1.5.6

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

func GetCompareURLEqualFunc added in v1.5.6

func GetCompareURLEqualFunc() CompareURLEqualFunc

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 added in v1.5.5

type Option func(*URL)

Option accepts url Option will define a function of handling URL

func WithIp

func WithIp(ip string) Option

WithIp sets ip for url

func WithLocation added in v1.2.0

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 sets params for 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 added in v1.2.0

func WithToken(token string) Option

WithToken sets token for url

func WithUsername

func WithUsername(username string) Option

WithUsername sets username for url

type RPCService

type RPCService interface {
	// Reference:
	// rpc service id or reference id
	Reference() string
}

RPCService rpc service interface

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 added in v1.5.0

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 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. 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) AddParam

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

AddParam will add the key-value pair

func (*URL) AddParamAvoidNil added in v1.5.3

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

AddParamAvoidNil will add key-value pair

func (*URL) Clone added in v1.2.0

func (c *URL) Clone() *URL

Clone will copy the url

func (*URL) CloneExceptParams added in v1.5.0

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

func (*URL) CloneWithParams added in v1.5.0

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

Copy url based on the reserved parameter's keys.

func (*URL) ColonSeparatedKey added in v1.4.0

func (c *URL) ColonSeparatedKey() string

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

func (*URL) Compare added in v1.5.5

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

func (*URL) DelParam added in v1.5.6

func (c *URL) DelParam(key string)

DelParam will delete the given key from the url

func (*URL) EncodedServiceKey added in v1.2.0

func (c *URL) EncodedServiceKey() string

EncodedServiceKey encode the service key

func (*URL) GetCacheInvokerMapKey added in v1.5.7

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 added in v1.3.0

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 added in v1.5.5

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

GetMethodParamIntValue gets int method param

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 added in v1.5.5

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

GetParamByIntValue gets int value by @key

func (*URL) GetParamDuration added in v1.5.8

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 added in v1.5.5

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

GetParamInt32 gets int32 value by @key

func (*URL) GetParams added in v1.2.0

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) Key

func (c *URL) Key() string

Key gets key

func (*URL) RangeParams added in v1.2.0

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

RangeParams will iterate the params

func (*URL) ReplaceParams added in v1.5.6

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 added in v1.2.0

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 added in v1.2.0

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.

type URLSlice added in v1.5.0

type URLSlice []*URL

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

func (URLSlice) Len added in v1.5.0

func (s URLSlice) Len() int

nolint

func (URLSlice) Less added in v1.5.0

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

nolint

func (URLSlice) Swap added in v1.5.0

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