Documentation ¶
Overview ¶
Package core is motan-go base package. contains base struct, interface and default implement.
Index ¶
- Constants
- Variables
- func CanSetContext(s interface{}, context *Context)
- func FirstUpper(s string) string
- func GetAllGroups(gr GroupDiscoverableRegistry) []string
- func GetLocalIP() string
- func GetLocalIPs() []string
- func GetReqInfo(request Request) string
- func GetURLFilters(url *URL, extFactory ExtensionFactory) (clusterFilter ClusterFilter, endpointFilters []Filter)
- func HandlePanic(f func())
- func Initialize(s interface{})
- func InterfaceToString(in interface{}) string
- func IsSame(m1 map[string]string, m2 map[string]string, key string, defaultValue string) bool
- func ListenUnixSock(unixSockAddr string) (net.Listener, error)
- func ParseExportInfo(export string) (string, int, error)
- func RegistLocalProvider(service string, provider Provider)
- func ServiceInGroup(sr ServiceDiscoverableRegistry, group string, service string) bool
- func SliceShuffle(slice []string) []string
- func TrimSplit(s string, sep string) []string
- type AsyncResult
- type AtomicString
- type Attachment
- type BytesBuffer
- func (b *BytesBuffer) Bytes() []byte
- func (b *BytesBuffer) Cap() int
- func (b *BytesBuffer) GetRPos() int
- func (b *BytesBuffer) GetWPos() int
- func (b *BytesBuffer) Len() int
- func (b *BytesBuffer) Next(n int) ([]byte, error)
- func (b *BytesBuffer) Read(p []byte) (n int, err error)
- func (b *BytesBuffer) ReadByte() (byte, error)
- func (b *BytesBuffer) ReadFull(p []byte) error
- func (b *BytesBuffer) ReadInt() (int, error)
- func (b *BytesBuffer) ReadUint16() (n uint16, err error)
- func (b *BytesBuffer) ReadUint32() (n uint32, err error)
- func (b *BytesBuffer) ReadUint64() (n uint64, err error)
- func (b *BytesBuffer) ReadVarint() (x uint64, err error)
- func (b *BytesBuffer) ReadZigzag32() (x uint64, err error)
- func (b *BytesBuffer) ReadZigzag64() (x uint64, err error)
- func (b *BytesBuffer) Remain() int
- func (b *BytesBuffer) Reset()
- func (b *BytesBuffer) SetRPos(pos int)
- func (b *BytesBuffer) SetWPos(pos int)
- func (b *BytesBuffer) Write(bytes []byte)
- func (b *BytesBuffer) WriteByte(c byte)
- func (b *BytesBuffer) WriteUint16(u uint16)
- func (b *BytesBuffer) WriteUint32(u uint32)
- func (b *BytesBuffer) WriteUint64(u uint64)
- func (b *BytesBuffer) WriteVarint(u uint64) int
- func (b *BytesBuffer) WriteZigzag32(u uint32) int
- func (b *BytesBuffer) WriteZigzag64(u uint64) int
- type Caller
- type Cloneable
- type ClusterFilter
- type CommandNotifyListener
- type Context
- type CopyOnWriteMap
- func (m *CopyOnWriteMap) Delete(key interface{}) (pv interface{})
- func (m *CopyOnWriteMap) Len() int
- func (m *CopyOnWriteMap) Load(key interface{}) (interface{}, bool)
- func (m *CopyOnWriteMap) LoadOrNil(key interface{}) interface{}
- func (m *CopyOnWriteMap) Range(f func(k, v interface{}) bool)
- func (m *CopyOnWriteMap) Store(key, value interface{})
- func (m *CopyOnWriteMap) Swap(newMap map[interface{}]interface{}) map[interface{}]interface{}
- type DefaultExtensionFactory
- func (d *DefaultExtensionFactory) GetEndPoint(url *URL) EndPoint
- func (d *DefaultExtensionFactory) GetFilter(name string) Filter
- func (d *DefaultExtensionFactory) GetHa(url *URL) HaStrategy
- func (d *DefaultExtensionFactory) GetLB(url *URL) LoadBalance
- func (d *DefaultExtensionFactory) GetMessageHandler(name string) MessageHandler
- func (d *DefaultExtensionFactory) GetProvider(url *URL) Provider
- func (d *DefaultExtensionFactory) GetRegistry(url *URL) Registry
- func (d *DefaultExtensionFactory) GetSerialization(name string, id int) Serialization
- func (d *DefaultExtensionFactory) GetServer(url *URL) Server
- func (d *DefaultExtensionFactory) Initialize()
- func (d *DefaultExtensionFactory) RegistExtEndpoint(name string, newEndpoint NewEndpointFunc)
- func (d *DefaultExtensionFactory) RegistExtFilter(name string, newFilter DefaultFilterFunc)
- func (d *DefaultExtensionFactory) RegistExtHa(name string, newHa NewHaFunc)
- func (d *DefaultExtensionFactory) RegistExtLb(name string, newLb NewLbFunc)
- func (d *DefaultExtensionFactory) RegistExtProvider(name string, newProvider NewProviderFunc)
- func (d *DefaultExtensionFactory) RegistExtRegistry(name string, newRegistry NewRegistryFunc)
- func (d *DefaultExtensionFactory) RegistExtServer(name string, newServer NewServerFunc)
- func (d *DefaultExtensionFactory) RegistryExtMessageHandler(name string, newMessage NewMessageHandlerFunc)
- func (d *DefaultExtensionFactory) RegistryExtSerialization(name string, id int, newSerialization NewSerializationFunc)
- type DefaultFilterFunc
- type DeserializableValue
- type Destroyable
- type DiscoverCommand
- type DiscoverService
- type EndPoint
- type EndPointFilter
- type Exception
- type Exporter
- type ExtensionFactory
- type Filter
- type FilterEndPoint
- func (f *FilterEndPoint) Call(request Request) Response
- func (f *FilterEndPoint) Destroy()
- func (f *FilterEndPoint) GetName() string
- func (f *FilterEndPoint) GetURL() *URL
- func (f *FilterEndPoint) IsAvailable() bool
- func (f *FilterEndPoint) SetProxy(proxy bool)
- func (f *FilterEndPoint) SetSerialization(s Serialization)
- func (f *FilterEndPoint) SetURL(url *URL)
- type FinishHandleFunc
- type FinishHandler
- type GroupDiscoverableRegistry
- type HaStrategy
- type Identity
- type Initializable
- type LoadBalance
- type MessageHandler
- type MotanRequest
- func (m *MotanRequest) Clone() interface{}
- func (m *MotanRequest) GetArguments() []interface{}
- func (m *MotanRequest) GetAttachment(key string) string
- func (m *MotanRequest) GetAttachments() *StringMap
- func (m *MotanRequest) GetMethod() string
- func (m *MotanRequest) GetMethodDesc() string
- func (m *MotanRequest) GetRPCContext(canCreate bool) *RPCContext
- func (m *MotanRequest) GetRequestID() uint64
- func (m *MotanRequest) GetServiceName() string
- func (m *MotanRequest) ProcessDeserializable(toTypes []interface{}) error
- func (m *MotanRequest) SetArguments(arguments []interface{})
- func (m *MotanRequest) SetAttachment(key string, value string)
- type MotanResponse
- func (m *MotanResponse) GetAttachment(key string) string
- func (m *MotanResponse) GetAttachments() *StringMap
- func (m *MotanResponse) GetException() *Exception
- func (m *MotanResponse) GetProcessTime() int64
- func (m *MotanResponse) GetRPCContext(canCreate bool) *RPCContext
- func (m *MotanResponse) GetRequestID() uint64
- func (m *MotanResponse) GetValue() interface{}
- func (m *MotanResponse) ProcessDeserializable(toType interface{}) error
- func (m *MotanResponse) SetAttachment(key string, value string)
- func (m *MotanResponse) SetProcessTime(time int64)
- type Name
- type NewEndpointFunc
- type NewHaFunc
- type NewLbFunc
- type NewMessageHandlerFunc
- type NewProviderFunc
- type NewRegistryFunc
- type NewSerializationFunc
- type NewServerFunc
- type NotifyListener
- type Pinger
- type Provider
- type RPCContext
- type RegisterService
- type Registry
- type Request
- type Response
- type Serialization
- type Server
- type ServiceDiscoverableRegistry
- type SetContext
- type SnapshotConf
- type SnapshotService
- type Span
- type Status
- type StringMap
- func (m *StringMap) Copy() *StringMap
- func (m *StringMap) Delete(key string)
- func (m *StringMap) Len() int
- func (m *StringMap) Load(key string) (value string, ok bool)
- func (m *StringMap) LoadOrEmpty(key string) string
- func (m *StringMap) Range(f func(k, v string) bool)
- func (m *StringMap) RawMap() map[string]string
- func (m *StringMap) Store(key, value string)
- type Switcher
- type SwitcherListener
- type SwitcherManager
- type TCPKeepAliveListener
- type TestEndPoint
- func (t *TestEndPoint) Call(request Request) Response
- func (t *TestEndPoint) Destroy()
- func (t *TestEndPoint) GetName() string
- func (t *TestEndPoint) GetURL() *URL
- func (t *TestEndPoint) IsAvailable() bool
- func (t *TestEndPoint) SetProxy(proxy bool)
- func (t *TestEndPoint) SetSerialization(s Serialization)
- func (t *TestEndPoint) SetURL(url *URL)
- type TestEndPointFilter
- func (t *TestEndPointFilter) Filter(caller Caller, request Request) Response
- func (t *TestEndPointFilter) GetIndex() int
- func (t *TestEndPointFilter) GetName() string
- func (t *TestEndPointFilter) GetNext() EndPointFilter
- func (t *TestEndPointFilter) GetType() int32
- func (t *TestEndPointFilter) HasNext() bool
- func (t *TestEndPointFilter) NewFilter(url *URL) Filter
- func (t *TestEndPointFilter) SetNext(nextFilter EndPointFilter)
- type TestFilter
- func (t *TestFilter) Filter(haStrategy HaStrategy, loadBalance LoadBalance, request Request) Response
- func (t *TestFilter) GetIndex() int
- func (t *TestFilter) GetName() string
- func (t *TestFilter) GetNext() ClusterFilter
- func (t *TestFilter) GetType() int32
- func (t *TestFilter) HasNext() bool
- func (t *TestFilter) NewFilter(url *URL) Filter
- func (t *TestFilter) SetNext(nextFilter ClusterFilter)
- type TestHaStrategy
- type TestLoadBalance
- type TestObject
- type TestProvider
- type TestRegistry
- func (t *TestRegistry) Available(serverURL *URL)
- func (t *TestRegistry) Discover(url *URL) []*URL
- func (t *TestRegistry) DiscoverAllGroups() ([]string, error)
- func (t *TestRegistry) DiscoverAllServices(group string) ([]string, error)
- func (t *TestRegistry) GetName() string
- func (t *TestRegistry) GetRegisteredServices() []*URL
- func (t *TestRegistry) GetURL() *URL
- func (t *TestRegistry) InitRegistry()
- func (t *TestRegistry) Register(serverURL *URL)
- func (t *TestRegistry) SetURL(url *URL)
- func (t *TestRegistry) StartSnapshot(conf *SnapshotConf)
- func (t *TestRegistry) Subscribe(url *URL, listener NotifyListener)
- func (t *TestRegistry) UnRegister(serverURL *URL)
- func (t *TestRegistry) Unavailable(serverURL *URL)
- func (t *TestRegistry) Unsubscribe(url *URL, listener NotifyListener)
- type TraceContext
- type TracePolicyFunc
- type URL
- func (u *URL) CanServe(other *URL) bool
- func (u *URL) ClearCachedInfo()
- func (u *URL) Copy() *URL
- func (u *URL) GetAddressStr() string
- func (u *URL) GetIdentity() string
- func (u *URL) GetInt(key string) (int64, bool)
- func (u *URL) GetIntValue(key string, defaultValue int64) int64
- func (u *URL) GetMethodIntValue(method string, methodDesc string, key string, defaultValue int64) int64
- func (u *URL) GetMethodPositiveIntValue(method string, methodDesc string, key string, defaultValue int64) int64
- func (u *URL) GetParam(key string, defaultValue string) string
- func (u *URL) GetPortStr() string
- func (u *URL) GetPositiveIntValue(key string, defaultvalue int64) int64
- func (u *URL) GetStringParamsWithDefault(key string, defaultvalue string) string
- func (u *URL) GetTimeDuration(key string, unit time.Duration, defaultDuration time.Duration) time.Duration
- func (u *URL) MergeParams(params map[string]string)
- func (u *URL) PutParam(key string, value string)
- func (u *URL) ToExtInfo() string
- type WithURL
Constants ¶
const ( FrameworkException = iota // ServiceException : exception by service call ServiceException // BizException : exception by service implements BizException )
--------------all global public constants-------------- exception type
const ( // EndPointFilterType filter for endpoint EndPointFilterType = iota // ClusterFilterType filter for cluster ClusterFilterType )
filter type
const ( NodeTypeKey = "nodeType" Hakey = "haStrategy" Lbkey = "loadbalance" TimeOutKey = "requestTimeout" MinTimeOutKey = "minRequestTimeout" MaxTimeOutKey = "maxRequestTimeout" SessionTimeOutKey = "registrySessionTimeout" RetriesKey = "retries" ApplicationKey = "application" VersionKey = "version" FilterKey = "filter" RegistryKey = "registry" WeightKey = "weight" SerializationKey = "serialization" RefKey = "ref" ExportKey = "export" ModuleKey = "module" GroupKey = "group" ProviderKey = "provider" ProxyKey = "proxy" AddressKey = "address" GzipSizeKey = "mingzSize" HostKey = "host" RemoteIPKey = "remoteIP" ProxyRegistryKey = "proxyRegistry" ConnectTimeoutKey = "connectTimeout" ConnectRetryIntervalKey = "connectRetryInterval" ClientConnectionKey = "clientConnection" ErrorCountThresholdKey = "errorCountThreshold" KeepaliveIntervalKey = "keepaliveInterval" UnixSockKey = "unixSock" ManagementUnixSockKey = "managementUnixSock" ManagementPortRangeKey = "managementPortRange" HTTPProxyUnixSockKey = "httpProxyUnixSock" )
common url parameter key
const ( NodeTypeService = "service" NodeTypeReferer = "referer" NodeTypeAgent = "agent" )
nodeType
const ( Receive = "receive" Decode = "decode" Convert = "convert" ClFilter = "clusterFilter" EpFilterStart = "selectEndpoint" EpFilterEnd = "endpointFilter" Encode = "encode" Send = "send" )
trace span name
const ( ENoEndpoints = 1001 ENoChannel = 1002 )
errorCodes
const ( SwitcherSection = "switcher" // URLConfKey is config id // config Keys URLConfKey = "conf-id" )
const ( DefaultAttachmentSize = 16 DefaultRPCContextMetaSize = 8 ProtocolLocal = "local" )
const (
DefaultWriteTimeout = 5 * time.Second
)
const (
MetaUpstreamCode = "upstreamCode"
)
meta keys
Variables ¶
var ( // TracePolicy is trace policy for mesh request, this func is called by each request, trace will enable if this func return a TraceContext TracePolicy TracePolicyFunc = NoTrace // RandomTraceBase is random base for RandomTrace RandomTraceBase = 10 MaxTraceSize uint64 = 10000 )
var ( Port = flag.Int("port", 0, "agent listen port") Eport = flag.Int("eport", 0, "agent export service port when as a reverse proxy server") Hport = flag.Int("hport", 0, "http forward proxy server port") Mport = flag.Int("mport", 0, "agent manage port") Pidfile = flag.String("pidfile", "", "agent manage port") CfgFile = flag.String("c", "", "motan run conf") LocalIP = flag.String("localIP", "", "local ip for motan register") IDC = flag.String("idc", "", "the idc info for agent or client.") Pool = flag.String("pool", "", "application pool config. like 'application-idc-level'") Application = flag.String("application", "", "assist for application pool config.") Recover = flag.Bool("recover", false, "recover from accidental exit") )
all env flag in motan-go
var ErrNotEnough = errors.New("BytesBuffer: not enough bytes")
var ErrOverflow = errors.New("BytesBuffer: integer overflow")
var (
PanicStatFunc func()
)
Functions ¶
func CanSetContext ¶
func CanSetContext(s interface{}, context *Context)
CanSetContext :CanSetContext
func FirstUpper ¶
func GetAllGroups ¶
func GetAllGroups(gr GroupDiscoverableRegistry) []string
func GetReqInfo ¶
func GetURLFilters ¶
func GetURLFilters(url *URL, extFactory ExtensionFactory) (clusterFilter ClusterFilter, endpointFilters []Filter)
func HandlePanic ¶
func HandlePanic(f func())
func InterfaceToString ¶
func InterfaceToString(in interface{}) string
func ListenUnixSock ¶
ListenUnixSock try to listen a unix socket address this method using by create motan agent server, management server and http proxy server
func RegistLocalProvider ¶
func ServiceInGroup ¶
func ServiceInGroup(sr ServiceDiscoverableRegistry, group string, service string) bool
func SliceShuffle ¶
Types ¶
type AsyncResult ¶
type AsyncResult struct { StartTime int64 Done chan *AsyncResult Reply interface{} Error error }
AsyncResult : async call result
type AtomicString ¶
type AtomicString struct {
// contains filtered or unexported fields
}
func NewAtomicString ¶
func NewAtomicString(str string) *AtomicString
func (*AtomicString) Load ¶
func (s *AtomicString) Load() string
func (*AtomicString) Store ¶
func (s *AtomicString) Store(str string)
type Attachment ¶
type Attachment interface { GetAttachments() *StringMap GetAttachment(key string) string SetAttachment(key string, value string) }
Attachment : can get, set attachments.
type BytesBuffer ¶
type BytesBuffer struct {
// contains filtered or unexported fields
}
BytesBuffer is a variable-sized buffer of bytes with Read and Write methods. BytesBuffer is not thread safe for multi goroutine operation.
func CreateBytesBuffer ¶
func CreateBytesBuffer(data []byte) *BytesBuffer
CreateBytesBuffer create a BytesBuffer from data bytes
func CreateBytesBufferWithOrder ¶
func CreateBytesBufferWithOrder(data []byte, order binary.ByteOrder) *BytesBuffer
CreateBytesBufferWithOrder create a BytesBuffer from data bytes with bytes order
func NewBytesBuffer ¶
func NewBytesBuffer(initsize int) *BytesBuffer
NewBytesBuffer create a empty BytesBuffer with initial size
func NewBytesBufferWithOrder ¶
func NewBytesBufferWithOrder(initsize int, order binary.ByteOrder) *BytesBuffer
NewBytesBufferWithOrder create a empty BytesBuffer with initial size and byte order
func (*BytesBuffer) Bytes ¶
func (b *BytesBuffer) Bytes() []byte
func (*BytesBuffer) Cap ¶
func (b *BytesBuffer) Cap() int
func (*BytesBuffer) GetRPos ¶
func (b *BytesBuffer) GetRPos() int
GetRPos get the read position of BytesBuffer
func (*BytesBuffer) GetWPos ¶
func (b *BytesBuffer) GetWPos() int
GetWPos get the write position of BytesBuffer
func (*BytesBuffer) Len ¶
func (b *BytesBuffer) Len() int
func (*BytesBuffer) ReadByte ¶
func (b *BytesBuffer) ReadByte() (byte, error)
func (*BytesBuffer) ReadFull ¶
func (b *BytesBuffer) ReadFull(p []byte) error
func (*BytesBuffer) ReadUint16 ¶
func (b *BytesBuffer) ReadUint16() (n uint16, err error)
func (*BytesBuffer) ReadUint32 ¶
func (b *BytesBuffer) ReadUint32() (n uint32, err error)
func (*BytesBuffer) ReadUint64 ¶
func (b *BytesBuffer) ReadUint64() (n uint64, err error)
func (*BytesBuffer) ReadVarint ¶
func (b *BytesBuffer) ReadVarint() (x uint64, err error)
func (*BytesBuffer) ReadZigzag32 ¶
func (b *BytesBuffer) ReadZigzag32() (x uint64, err error)
func (*BytesBuffer) ReadZigzag64 ¶
func (b *BytesBuffer) ReadZigzag64() (x uint64, err error)
func (*BytesBuffer) Remain ¶
func (b *BytesBuffer) Remain() int
func (*BytesBuffer) Reset ¶
func (b *BytesBuffer) Reset()
func (*BytesBuffer) SetRPos ¶
func (b *BytesBuffer) SetRPos(pos int)
SetRPos get the read position of BytesBuffer
func (*BytesBuffer) SetWPos ¶
func (b *BytesBuffer) SetWPos(pos int)
SetWPos set the write position of BytesBuffer
func (*BytesBuffer) Write ¶
func (b *BytesBuffer) Write(bytes []byte)
Write write a byte array append the BytesBuffer, and the wpos will increase len(bytes)
func (*BytesBuffer) WriteByte ¶
func (b *BytesBuffer) WriteByte(c byte)
WriteByte write a byte append the BytesBuffer, the wpos will increase one
func (*BytesBuffer) WriteUint16 ¶
func (b *BytesBuffer) WriteUint16(u uint16)
WriteUint16 write a uint16 append the BytesBuffer acording to buffer's order
func (*BytesBuffer) WriteUint32 ¶
func (b *BytesBuffer) WriteUint32(u uint32)
func (*BytesBuffer) WriteUint64 ¶
func (b *BytesBuffer) WriteUint64(u uint64)
func (*BytesBuffer) WriteVarint ¶
func (b *BytesBuffer) WriteVarint(u uint64) int
func (*BytesBuffer) WriteZigzag32 ¶
func (b *BytesBuffer) WriteZigzag32(u uint32) int
func (*BytesBuffer) WriteZigzag64 ¶
func (b *BytesBuffer) WriteZigzag64(u uint64) int
type Caller ¶
type Caller interface { WithURL Status Call(request Request) Response Destroyable }
Caller : can process a motan request. the call maybe process from remote by endpoint, maybe process by some kinds of provider
type Cloneable ¶
type Cloneable interface {
Clone() interface{}
}
Cloneable : can clone itself, the return type interface{} must be the type which implement this interface
type ClusterFilter ¶
type ClusterFilter interface { Filter SetNext(nextFilter ClusterFilter) GetNext() ClusterFilter //Filter for Cluster Filter(haStrategy HaStrategy, loadBalance LoadBalance, request Request) Response }
ClusterFilter : filter for cluster
func GetLastClusterFilter ¶
func GetLastClusterFilter() ClusterFilter
type CommandNotifyListener ¶
type CommandNotifyListener interface { Identity NotifyCommand(registryURL *URL, commandType int, commandInfo string) }
CommandNotifyListener : support command notify
type Context ¶
type Context struct { ConfigFile string Config *cfg.Config RegistryURLs map[string]*URL RefersURLs map[string]*URL HTTPClientURLs map[string]*URL BasicReferURLs map[string]*URL ServiceURLs map[string]*URL BasicServiceURLs map[string]*URL AgentURL *URL ClientURL *URL ServerURL *URL // contains filtered or unexported fields }
Context for agent, client, server. context is created depends on config file
func NewContextFromConfig ¶
func (*Context) Initialize ¶
func (c *Context) Initialize()
type CopyOnWriteMap ¶
type CopyOnWriteMap struct {
// contains filtered or unexported fields
}
func NewCopyOnWriteMap ¶
func NewCopyOnWriteMap() *CopyOnWriteMap
func (*CopyOnWriteMap) Delete ¶
func (m *CopyOnWriteMap) Delete(key interface{}) (pv interface{})
func (*CopyOnWriteMap) Len ¶
func (m *CopyOnWriteMap) Len() int
func (*CopyOnWriteMap) Load ¶
func (m *CopyOnWriteMap) Load(key interface{}) (interface{}, bool)
func (*CopyOnWriteMap) LoadOrNil ¶
func (m *CopyOnWriteMap) LoadOrNil(key interface{}) interface{}
func (*CopyOnWriteMap) Range ¶
func (m *CopyOnWriteMap) Range(f func(k, v interface{}) bool)
func (*CopyOnWriteMap) Store ¶
func (m *CopyOnWriteMap) Store(key, value interface{})
func (*CopyOnWriteMap) Swap ¶
func (m *CopyOnWriteMap) Swap(newMap map[interface{}]interface{}) map[interface{}]interface{}
type DefaultExtensionFactory ¶
type DefaultExtensionFactory struct {
// contains filtered or unexported fields
}
func (*DefaultExtensionFactory) GetEndPoint ¶
func (d *DefaultExtensionFactory) GetEndPoint(url *URL) EndPoint
func (*DefaultExtensionFactory) GetFilter ¶
func (d *DefaultExtensionFactory) GetFilter(name string) Filter
func (*DefaultExtensionFactory) GetHa ¶
func (d *DefaultExtensionFactory) GetHa(url *URL) HaStrategy
func (*DefaultExtensionFactory) GetLB ¶
func (d *DefaultExtensionFactory) GetLB(url *URL) LoadBalance
func (*DefaultExtensionFactory) GetMessageHandler ¶
func (d *DefaultExtensionFactory) GetMessageHandler(name string) MessageHandler
func (*DefaultExtensionFactory) GetProvider ¶
func (d *DefaultExtensionFactory) GetProvider(url *URL) Provider
func (*DefaultExtensionFactory) GetRegistry ¶
func (d *DefaultExtensionFactory) GetRegistry(url *URL) Registry
func (*DefaultExtensionFactory) GetSerialization ¶
func (d *DefaultExtensionFactory) GetSerialization(name string, id int) Serialization
func (*DefaultExtensionFactory) GetServer ¶
func (d *DefaultExtensionFactory) GetServer(url *URL) Server
func (*DefaultExtensionFactory) Initialize ¶
func (d *DefaultExtensionFactory) Initialize()
func (*DefaultExtensionFactory) RegistExtEndpoint ¶
func (d *DefaultExtensionFactory) RegistExtEndpoint(name string, newEndpoint NewEndpointFunc)
func (*DefaultExtensionFactory) RegistExtFilter ¶
func (d *DefaultExtensionFactory) RegistExtFilter(name string, newFilter DefaultFilterFunc)
func (*DefaultExtensionFactory) RegistExtHa ¶
func (d *DefaultExtensionFactory) RegistExtHa(name string, newHa NewHaFunc)
func (*DefaultExtensionFactory) RegistExtLb ¶
func (d *DefaultExtensionFactory) RegistExtLb(name string, newLb NewLbFunc)
func (*DefaultExtensionFactory) RegistExtProvider ¶
func (d *DefaultExtensionFactory) RegistExtProvider(name string, newProvider NewProviderFunc)
func (*DefaultExtensionFactory) RegistExtRegistry ¶
func (d *DefaultExtensionFactory) RegistExtRegistry(name string, newRegistry NewRegistryFunc)
func (*DefaultExtensionFactory) RegistExtServer ¶
func (d *DefaultExtensionFactory) RegistExtServer(name string, newServer NewServerFunc)
func (*DefaultExtensionFactory) RegistryExtMessageHandler ¶
func (d *DefaultExtensionFactory) RegistryExtMessageHandler(name string, newMessage NewMessageHandlerFunc)
func (*DefaultExtensionFactory) RegistryExtSerialization ¶
func (d *DefaultExtensionFactory) RegistryExtSerialization(name string, id int, newSerialization NewSerializationFunc)
type DefaultFilterFunc ¶
type DefaultFilterFunc func() Filter
type DeserializableValue ¶
type DeserializableValue struct { Serialization Serialization Body []byte }
DeserializableValue : for lazy deserialize
func (*DeserializableValue) Deserialize ¶
func (d *DeserializableValue) Deserialize(v interface{}) (interface{}, error)
Deserialize : Deserialize
func (*DeserializableValue) DeserializeMulti ¶
func (d *DeserializableValue) DeserializeMulti(v []interface{}) ([]interface{}, error)
DeserializeMulti : DeserializeMulti
type DiscoverCommand ¶
type DiscoverCommand interface { SubscribeCommand(url *URL, listener CommandNotifyListener) UnSubscribeCommand(url *URL, listener CommandNotifyListener) DiscoverCommand(url *URL) string }
DiscoverCommand : discover command for client or agent
type DiscoverService ¶
type DiscoverService interface { Subscribe(url *URL, listener NotifyListener) Unsubscribe(url *URL, listener NotifyListener) Discover(url *URL) []*URL }
DiscoverService : discover service for cluster
type EndPoint ¶
type EndPoint interface { Name Caller SetSerialization(s Serialization) SetProxy(proxy bool) }
EndPoint : can process a remote rpc call
type EndPointFilter ¶
type EndPointFilter interface { Filter SetNext(nextFilter EndPointFilter) GetNext() EndPointFilter //Filter for endpoint Filter(caller Caller, request Request) Response }
EndPointFilter : filter for endpoint
func GetLastEndPointFilter ¶
func GetLastEndPointFilter() EndPointFilter
type Exception ¶
type Exception struct { ErrCode int `json:"errcode"` ErrMsg string `json:"errmsg"` ErrType int `json:"errtype"` }
Exception :Exception
type Exporter ¶
type Exporter interface { Export(server Server, extFactory ExtensionFactory, context *Context) error Unexport() error SetProvider(provider Provider) GetProvider() Provider Available() IsAvailable() bool WithURL }
Exporter : export and manage a service. one exporter bind with a service
type ExtensionFactory ¶
type ExtensionFactory interface { GetHa(url *URL) HaStrategy GetLB(url *URL) LoadBalance GetFilter(name string) Filter GetRegistry(url *URL) Registry GetEndPoint(url *URL) EndPoint GetProvider(url *URL) Provider GetServer(url *URL) Server GetMessageHandler(name string) MessageHandler GetSerialization(name string, id int) Serialization RegistExtFilter(name string, newFilter DefaultFilterFunc) RegistExtHa(name string, newHa NewHaFunc) RegistExtLb(name string, newLb NewLbFunc) RegistExtEndpoint(name string, newEndpoint NewEndpointFunc) RegistExtProvider(name string, newProvider NewProviderFunc) RegistExtRegistry(name string, newRegistry NewRegistryFunc) RegistExtServer(name string, newServer NewServerFunc) RegistryExtMessageHandler(name string, newMessage NewMessageHandlerFunc) RegistryExtSerialization(name string, id int, newSerialization NewSerializationFunc) }
ExtensionFactory : can regiser and get all kinds of extension implements.
type Filter ¶
type Filter interface { Name // filter must be prototype NewFilter(url *URL) Filter HasNext() bool GetIndex() int GetType() int32 }
Filter : filter request or response in a call processing
type FilterEndPoint ¶
type FilterEndPoint struct { URL *URL Filter EndPointFilter StatusFilters []Status Caller Caller }
func (*FilterEndPoint) Call ¶
func (f *FilterEndPoint) Call(request Request) Response
func (*FilterEndPoint) Destroy ¶
func (f *FilterEndPoint) Destroy()
func (*FilterEndPoint) GetName ¶
func (f *FilterEndPoint) GetName() string
func (*FilterEndPoint) GetURL ¶
func (f *FilterEndPoint) GetURL() *URL
func (*FilterEndPoint) IsAvailable ¶
func (f *FilterEndPoint) IsAvailable() bool
func (*FilterEndPoint) SetProxy ¶
func (f *FilterEndPoint) SetProxy(proxy bool)
func (*FilterEndPoint) SetSerialization ¶
func (f *FilterEndPoint) SetSerialization(s Serialization)
func (*FilterEndPoint) SetURL ¶
func (f *FilterEndPoint) SetURL(url *URL)
type FinishHandleFunc ¶
type FinishHandleFunc func()
func (FinishHandleFunc) Handle ¶
func (f FinishHandleFunc) Handle()
type FinishHandler ¶
type FinishHandler interface {
Handle()
}
type HaStrategy ¶
type HaStrategy interface { Name WithURL Call(request Request, loadBalance LoadBalance) Response }
HaStrategy : high availability strategy
type LoadBalance ¶
type LoadBalance interface { OnRefresh(endpoints []EndPoint) Select(request Request) EndPoint SelectArray(request Request) []EndPoint SetWeight(weight string) }
LoadBalance : loadBalance for cluster
type MessageHandler ¶
type MessageHandler interface { Call(request Request) (res Response) AddProvider(p Provider) error RmProvider(p Provider) GetProvider(serviceName string) Provider }
MessageHandler : handler message(request) for Server
type MotanRequest ¶
type MotanRequest struct { RequestID uint64 ServiceName string Method string MethodDesc string Arguments []interface{} Attachment *StringMap RPCContext *RPCContext // contains filtered or unexported fields }
MotanRequest : Request default implement
func (*MotanRequest) Clone ¶
func (m *MotanRequest) Clone() interface{}
func (*MotanRequest) GetArguments ¶
func (m *MotanRequest) GetArguments() []interface{}
func (*MotanRequest) GetAttachment ¶
func (m *MotanRequest) GetAttachment(key string) string
GetAttachment GetAttachment
func (*MotanRequest) GetAttachments ¶
func (m *MotanRequest) GetAttachments() *StringMap
func (*MotanRequest) GetMethodDesc ¶
func (m *MotanRequest) GetMethodDesc() string
GetMethodDesc GetMethodDesc
func (*MotanRequest) GetRPCContext ¶
func (m *MotanRequest) GetRPCContext(canCreate bool) *RPCContext
func (*MotanRequest) GetRequestID ¶
func (m *MotanRequest) GetRequestID() uint64
func (*MotanRequest) GetServiceName ¶
func (m *MotanRequest) GetServiceName() string
GetServiceName GetServiceName
func (*MotanRequest) ProcessDeserializable ¶
func (m *MotanRequest) ProcessDeserializable(toTypes []interface{}) error
ProcessDeserializable : DeserializableValue to real params according toType some serialization can deserialize without toType, so nil toType can be accepted in these serializations
func (*MotanRequest) SetArguments ¶
func (m *MotanRequest) SetArguments(arguments []interface{})
func (*MotanRequest) SetAttachment ¶
func (m *MotanRequest) SetAttachment(key string, value string)
SetAttachment : SetAttachment
type MotanResponse ¶
type MotanResponse struct { RequestID uint64 Value interface{} Exception *Exception ProcessTime int64 Attachment *StringMap RPCContext *RPCContext // contains filtered or unexported fields }
func BuildExceptionResponse ¶
func BuildExceptionResponse(requestid uint64, e *Exception) *MotanResponse
func (*MotanResponse) GetAttachment ¶
func (m *MotanResponse) GetAttachment(key string) string
func (*MotanResponse) GetAttachments ¶
func (m *MotanResponse) GetAttachments() *StringMap
func (*MotanResponse) GetException ¶
func (m *MotanResponse) GetException() *Exception
func (*MotanResponse) GetProcessTime ¶
func (m *MotanResponse) GetProcessTime() int64
func (*MotanResponse) GetRPCContext ¶
func (m *MotanResponse) GetRPCContext(canCreate bool) *RPCContext
func (*MotanResponse) GetRequestID ¶
func (m *MotanResponse) GetRequestID() uint64
func (*MotanResponse) GetValue ¶
func (m *MotanResponse) GetValue() interface{}
func (*MotanResponse) ProcessDeserializable ¶
func (m *MotanResponse) ProcessDeserializable(toType interface{}) error
ProcessDeserializable : same with MotanRequest
func (*MotanResponse) SetAttachment ¶
func (m *MotanResponse) SetAttachment(key string, value string)
func (*MotanResponse) SetProcessTime ¶
func (m *MotanResponse) SetProcessTime(time int64)
type Name ¶
type Name interface {
GetName() string
}
Name is a interface can get and set name. especially for extension implements
type NewEndpointFunc ¶
type NewHaFunc ¶
type NewHaFunc func(url *URL) HaStrategy
type NewLbFunc ¶
type NewLbFunc func(url *URL) LoadBalance
type NewMessageHandlerFunc ¶
type NewMessageHandlerFunc func() MessageHandler
type NewProviderFunc ¶
type NewRegistryFunc ¶
type NewSerializationFunc ¶
type NewSerializationFunc func() Serialization
type NewServerFunc ¶
type NotifyListener ¶
NotifyListener : NotifyListener
type Pinger ¶
type Pinger struct { Interval time.Duration Timeout time.Duration Count int PacketsSent int PacketsRecv int Rtts []time.Duration Size int // contains filtered or unexported fields }
type RPCContext ¶
type RPCContext struct { ExtFactory ExtensionFactory OriginalMessage interface{} Oneway bool Proxy bool GzipSize int BodySize int SerializeNum int Serialized bool // for call AsyncCall bool Result *AsyncResult Reply interface{} Meta *StringMap // various time, it's owned by motan request context RequestSendTime time.Time RequestReceiveTime time.Time ResponseSendTime time.Time ResponseReceiveTime time.Time FinishHandlers []FinishHandler // trace context Tc *TraceContext }
RPCContext : Context for RPC call
func (*RPCContext) AddFinishHandler ¶
func (c *RPCContext) AddFinishHandler(handler FinishHandler)
func (*RPCContext) OnFinish ¶
func (c *RPCContext) OnFinish()
type RegisterService ¶
type RegisterService interface { Register(serverURL *URL) UnRegister(serverURL *URL) Available(serverURL *URL) GetRegisteredServices() []*URL }
RegisterService : register service for rpc server
type Registry ¶
type Registry interface { Name WithURL DiscoverService RegisterService SnapshotService }
Registry : can subscribe or register service
type Request ¶
type Request interface { Attachment Cloneable GetServiceName() string // service name e.g. request path.or interface name GetMethod() string GetMethodDesc() string GetArguments() []interface{} GetRequestID() uint64 GetRPCContext(canCreate bool) *RPCContext ProcessDeserializable(toTypes []interface{}) error }
Request : motan request
type Response ¶
type Response interface { Attachment GetValue() interface{} GetException() *Exception GetRequestID() uint64 GetProcessTime() int64 SetProcessTime(time int64) GetRPCContext(canCreate bool) *RPCContext ProcessDeserializable(toType interface{}) error }
Response : motan response
type Serialization ¶
type Serialization interface { GetSerialNum() int Serialize(v interface{}) ([]byte, error) DeSerialize(b []byte, v interface{}) (interface{}, error) SerializeMulti(v []interface{}) ([]byte, error) DeSerializeMulti(b []byte, v []interface{}) ([]interface{}, error) }
Serialization : Serialization
func GetSerialization ¶
func GetSerialization(url *URL, extFactory ExtensionFactory) Serialization
type Server ¶
type Server interface { WithURL Name Destroyable SetMessageHandler(mh MessageHandler) GetMessageHandler() MessageHandler Open(block bool, proxy bool, handler MessageHandler, extFactory ExtensionFactory) error }
Server : rpc server which listen port and process request
type SnapshotConf ¶
type SnapshotConf struct { // SnapshotInterval is the interval of creating snapshot SnapshotInterval time.Duration SnapshotDir string }
SnapshotConf is model for registry snapshot config.
type SnapshotService ¶
type SnapshotService interface {
StartSnapshot(conf *SnapshotConf)
}
SnapshotService : start registry snapshot
type Status ¶
type Status interface {
IsAvailable() bool
}
Status : for cluster or endpoint to check is available
type StringMap ¶
type StringMap struct {
// contains filtered or unexported fields
}
StringMap goroutine safe string map, this will just be used in few goroutines so just use a simple implementation
func NewStringMap ¶
func (*StringMap) LoadOrEmpty ¶
type Switcher ¶
type Switcher struct {
// contains filtered or unexported fields
}
func (*Switcher) Watch ¶
func (s *Switcher) Watch(listeners ...SwitcherListener)
type SwitcherListener ¶
type SwitcherListener interface {
Notify(value bool)
}
type SwitcherManager ¶
type SwitcherManager struct {
// contains filtered or unexported fields
}
func GetSwitcherManager ¶
func GetSwitcherManager() *SwitcherManager
func (*SwitcherManager) GetAllSwitchers ¶
func (s *SwitcherManager) GetAllSwitchers() map[string]bool
func (*SwitcherManager) GetSwitcher ¶
func (s *SwitcherManager) GetSwitcher(name string) *Switcher
func (*SwitcherManager) Register ¶
func (s *SwitcherManager) Register(name string, value bool, listeners ...SwitcherListener)
type TCPKeepAliveListener ¶
type TCPKeepAliveListener struct {
*net.TCPListener
}
type TestEndPoint ¶
func (*TestEndPoint) Call ¶
func (t *TestEndPoint) Call(request Request) Response
func (*TestEndPoint) Destroy ¶
func (t *TestEndPoint) Destroy()
func (*TestEndPoint) GetName ¶
func (t *TestEndPoint) GetName() string
func (*TestEndPoint) GetURL ¶
func (t *TestEndPoint) GetURL() *URL
func (*TestEndPoint) IsAvailable ¶
func (t *TestEndPoint) IsAvailable() bool
func (*TestEndPoint) SetProxy ¶
func (t *TestEndPoint) SetProxy(proxy bool)
func (*TestEndPoint) SetSerialization ¶
func (t *TestEndPoint) SetSerialization(s Serialization)
func (*TestEndPoint) SetURL ¶
func (t *TestEndPoint) SetURL(url *URL)
type TestEndPointFilter ¶
func (*TestEndPointFilter) Filter ¶
func (t *TestEndPointFilter) Filter(caller Caller, request Request) Response
func (*TestEndPointFilter) GetIndex ¶
func (t *TestEndPointFilter) GetIndex() int
func (*TestEndPointFilter) GetName ¶
func (t *TestEndPointFilter) GetName() string
func (*TestEndPointFilter) GetNext ¶
func (t *TestEndPointFilter) GetNext() EndPointFilter
func (*TestEndPointFilter) GetType ¶
func (t *TestEndPointFilter) GetType() int32
func (*TestEndPointFilter) HasNext ¶
func (t *TestEndPointFilter) HasNext() bool
func (*TestEndPointFilter) NewFilter ¶
func (t *TestEndPointFilter) NewFilter(url *URL) Filter
func (*TestEndPointFilter) SetNext ¶
func (t *TestEndPointFilter) SetNext(nextFilter EndPointFilter)
type TestFilter ¶
func (*TestFilter) Filter ¶
func (t *TestFilter) Filter(haStrategy HaStrategy, loadBalance LoadBalance, request Request) Response
func (*TestFilter) GetIndex ¶
func (t *TestFilter) GetIndex() int
func (*TestFilter) GetName ¶
func (t *TestFilter) GetName() string
func (*TestFilter) GetNext ¶
func (t *TestFilter) GetNext() ClusterFilter
func (*TestFilter) GetType ¶
func (t *TestFilter) GetType() int32
func (*TestFilter) HasNext ¶
func (t *TestFilter) HasNext() bool
func (*TestFilter) NewFilter ¶
func (t *TestFilter) NewFilter(url *URL) Filter
func (*TestFilter) SetNext ¶
func (t *TestFilter) SetNext(nextFilter ClusterFilter)
type TestHaStrategy ¶
type TestHaStrategy struct {
URL *URL
}
func (*TestHaStrategy) Call ¶
func (t *TestHaStrategy) Call(request Request, loadBalance LoadBalance) Response
func (*TestHaStrategy) GetName ¶
func (t *TestHaStrategy) GetName() string
func (*TestHaStrategy) GetURL ¶
func (t *TestHaStrategy) GetURL() *URL
func (*TestHaStrategy) SetURL ¶
func (t *TestHaStrategy) SetURL(url *URL)
type TestLoadBalance ¶
type TestLoadBalance struct {
Endpoints []EndPoint
}
func (*TestLoadBalance) OnRefresh ¶
func (t *TestLoadBalance) OnRefresh(endpoints []EndPoint)
func (*TestLoadBalance) Select ¶
func (t *TestLoadBalance) Select(request Request) EndPoint
func (*TestLoadBalance) SelectArray ¶
func (t *TestLoadBalance) SelectArray(request Request) []EndPoint
func (*TestLoadBalance) SetWeight ¶
func (t *TestLoadBalance) SetWeight(weight string)
type TestObject ¶
type TestObject struct {
Str string
}
type TestProvider ¶
type TestProvider struct {
URL *URL
}
func (*TestProvider) Call ¶
func (t *TestProvider) Call(request Request) Response
func (*TestProvider) Destroy ¶
func (t *TestProvider) Destroy()
func (*TestProvider) GetPath ¶
func (t *TestProvider) GetPath() string
func (*TestProvider) GetURL ¶
func (t *TestProvider) GetURL() *URL
func (*TestProvider) IsAvailable ¶
func (t *TestProvider) IsAvailable() bool
func (*TestProvider) SetService ¶
func (t *TestProvider) SetService(s interface{})
func (*TestProvider) SetURL ¶
func (t *TestProvider) SetURL(url *URL)
type TestRegistry ¶
func (*TestRegistry) Available ¶
func (t *TestRegistry) Available(serverURL *URL)
func (*TestRegistry) Discover ¶
func (t *TestRegistry) Discover(url *URL) []*URL
func (*TestRegistry) DiscoverAllGroups ¶
func (t *TestRegistry) DiscoverAllGroups() ([]string, error)
func (*TestRegistry) DiscoverAllServices ¶
func (t *TestRegistry) DiscoverAllServices(group string) ([]string, error)
func (*TestRegistry) GetName ¶
func (t *TestRegistry) GetName() string
func (*TestRegistry) GetRegisteredServices ¶
func (t *TestRegistry) GetRegisteredServices() []*URL
func (*TestRegistry) GetURL ¶
func (t *TestRegistry) GetURL() *URL
func (*TestRegistry) InitRegistry ¶
func (t *TestRegistry) InitRegistry()
func (*TestRegistry) Register ¶
func (t *TestRegistry) Register(serverURL *URL)
func (*TestRegistry) SetURL ¶
func (t *TestRegistry) SetURL(url *URL)
func (*TestRegistry) StartSnapshot ¶
func (t *TestRegistry) StartSnapshot(conf *SnapshotConf)
func (*TestRegistry) Subscribe ¶
func (t *TestRegistry) Subscribe(url *URL, listener NotifyListener)
func (*TestRegistry) UnRegister ¶
func (t *TestRegistry) UnRegister(serverURL *URL)
func (*TestRegistry) Unavailable ¶
func (t *TestRegistry) Unavailable(serverURL *URL)
func (*TestRegistry) Unsubscribe ¶
func (t *TestRegistry) Unsubscribe(url *URL, listener NotifyListener)
type TraceContext ¶
type TraceContext struct { Rid uint64 `json:"requestid"` Addr string `json:"address"` Values map[string]interface{} `json:"values"` ReqSpans []*Span `json:"request_spans"` ResSpans []*Span `json:"response_spans"` // contains filtered or unexported fields }
func AlwaysTrace ¶
func AlwaysTrace(rid uint64, ext *StringMap) *TraceContext
AlwaysTrace : trace every request unless the tracecontext size over MaxTraceSize.
func GetTraceContexts ¶
func GetTraceContexts() []*TraceContext
GetTraceContexts get && remove all TraceContext in holder, and create a new TraceContext holder.
func NewTraceContext ¶
func NewTraceContext(rid uint64) *TraceContext
NewTraceContext : create a new TraceContext and hold to holder. it will return nil, if TraceContext size of holder is over MaxTraceSize.
func NoTrace ¶
func NoTrace(rid uint64, ext *StringMap) *TraceContext
NoTrace : not trace. default trace policy.
func RandomTrace ¶
func RandomTrace(rid uint64, ext *StringMap) *TraceContext
RandomTrace : trace ratio is 1/RandomTraceBase
func (*TraceContext) PutReqSpan ¶
func (t *TraceContext) PutReqSpan(span *Span)
PutReqSpan : put a trace Span at request phase
func (*TraceContext) PutResSpan ¶
func (t *TraceContext) PutResSpan(span *Span)
PutResSpan : put a trace Span at response phase
type TracePolicyFunc ¶
type TracePolicyFunc func(rid uint64, ext *StringMap) *TraceContext
type URL ¶
type URL struct { Protocol string `json:"protocol"` Host string `json:"host"` Port int `json:"port"` Path string `json:"path"` //e.g. service name Group string `json:"group"` Parameters map[string]string `json:"parameters"` // contains filtered or unexported fields }
func FromExtInfo ¶
func (*URL) ClearCachedInfo ¶
func (u *URL) ClearCachedInfo()
func (*URL) GetAddressStr ¶
func (*URL) GetIdentity ¶
GetIdentity return the identity of url. identity info includes protocol, host, port, path, group the identity will cached, so must clear cached info after update above info by calling ClearCachedInfo()
func (*URL) GetMethodIntValue ¶
func (*URL) GetMethodPositiveIntValue ¶
func (*URL) GetPortStr ¶
func (*URL) GetPositiveIntValue ¶
func (*URL) GetStringParamsWithDefault ¶
func (*URL) GetTimeDuration ¶
func (u *URL) GetTimeDuration(key string, unit time.Duration, defaultDuration time.Duration) time.Duration
GetTimeDuration get time duration from params.