Documentation
¶
Overview ¶
包含服务注册、服务发现相关的定义、实现
Index ¶
- Constants
- Variables
- func AccessLog() gin.HandlerFunc
- func ContextHeadUnaryClientInterceptor() grpc.UnaryClientInterceptor
- func ContextSetErrCode(ctx context.Context, errCode int)
- func DisableContextCancel() gin.HandlerFunc
- func FactoryHealthCheck() xhttp.HandleRequest
- func FactoryMD5() xhttp.HandleRequest
- func FactoryRestart() xhttp.HandleRequest
- func GetAPIRequestCountMetricV2() xmetric.Counter
- func GetAPIRequestTimeMetricV2() xmetric.Histogram
- func GetCallerFromBaggage(ctx context.Context) string
- func GetConfigCenter() xconfig.ConfigCenter
- func GetDBRequestCountMetric() xmetric.Counter
- func GetDBRequestTimeMetric() xmetric.Histogram
- func GetFuncName(index int) string
- func GetFuncNameWithCtx(ctx context.Context, index int) string
- func GetFuncRetry(servKey, funcName string) int
- func GetFuncRetryInner(confCenter xconfig.ConfigCenter, servKey, funcName string) int
- func GetFuncTimeout(servKey, funcName string, defaultTime time.Duration) time.Duration
- func GetFuncTimeoutInner(confCenter xconfig.ConfigCenter, servKey, funcName string, ...) time.Duration
- func GetGroupAndService() (group, service string)
- func GetInterfaceRateLimitRegistry() registry.InterfaceRateLimitRegistry
- func GetLogCountMetric() xmetric.Counter
- func GetProcessorAddress(processorName string) (addr string)
- func GetServId() (servId int)
- func GetServName() (servName string)
- func GetSlaDurationMetric() xmetric.Histogram
- func GetSlaRequestTotalMetric() xmetric.Counter
- func Init(etcdAddrs []string, baseLoc string, servLoc, servKey, logDir string, ...) error
- func InjectFromRequest() gin.HandlerFunc
- func LaneInfoUnaryClientInterceptor() grpc.UnaryClientInterceptor
- func MasterSlave(etcdAddrs []string, baseLoc string, initLogic func(ServBase) error, ...) error
- func Metric() gin.HandlerFunc
- func NewGinServer() *gin.Engine
- func NotFound() gin.HandlerFunc
- func ParseUriApi(uri string) string
- func RateLimit() gin.HandlerFunc
- func Recovery() gin.HandlerFunc
- func Serve(etcdAddrs []string, baseLoc string, initLogic func(ServBase) error, ...) error
- func ServeForTest(etcdAddrs []string, baseLoc, servLoc string, initLogic func(ServBase) error) error
- func Test(etcdAddrs []string, baseLoc, servLoc string, initLogic func(ServBase) error) error
- func Trace() gin.HandlerFunc
- type Addr
- type BaseConfig
- type Breaker
- type BreakerStat
- type ClientEtcdV2
- func (m *ClientEtcdV2) GetAllServAddr(processor string) []*ServInfo
- func (m *ClientEtcdV2) GetAllServAddrWithGroup(group, processor string) []*ServInfo
- func (m *ClientEtcdV2) GetServAddr(processor, key string) *ServInfo
- func (m *ClientEtcdV2) GetServAddrWithGroup(group string, processor, key string) *ServInfo
- func (m *ClientEtcdV2) GetServAddrWithServid(servid int, processor, key string) *ServInfo
- func (m *ClientEtcdV2) RegisterDeleteAddrHandler(handle deleteAddrHandler)
- func (m *ClientEtcdV2) ServKey() string
- func (m *ClientEtcdV2) ServPath() string
- func (m *ClientEtcdV2) String() string
- type ClientGrpc
- func (m *ClientGrpc) CustomizedRouteRpc(getProvider func() *Provider, fnrpc func(interface{}) error) error
- func (m *ClientGrpc) DirectRouteRpc(provider *Provider, fnrpc func(interface{}) error) error
- func (fs *ClientGrpc) GetFallbackFunc(name string) fallbackFunc
- func (fs *ClientGrpc) RegisterFallbackFunc(name string, fallback fallbackFunc)
- func (m *ClientGrpc) Rpc(hashKey string, fnrpc func(interface{}) error) error
- func (m *ClientGrpc) RpcWithContext(ctx context.Context, hashKey string, fnrpc func(interface{}) error) error
- func (m *ClientGrpc) RpcWithContextV2(ctx context.Context, hashKey string, ...) error
- func (m *ClientGrpc) SetConfigCenter(configCenter xconfig.ConfigCenter)
- type ClientLookup
- type ClientPool
- type ClientThrift
- func NewClientThrift(cb ClientLookup, processor string, ...) *ClientThrift
- func NewClientThriftByAddrRouter(cb ClientLookup, processor string, ...) *ClientThrift
- func NewClientThriftByConcurrentRouter(cb ClientLookup, processor string, ...) *ClientThrift
- func NewClientThriftWithRouterType(cb ClientLookup, processor string, ...) *ClientThrift
- func (fs *ClientThrift) GetFallbackFunc(name string) fallbackFunc
- func (fs *ClientThrift) RegisterFallbackFunc(name string, fallback fallbackFunc)
- func (m *ClientThrift) Rpc(hashKey string, timeout time.Duration, fnrpc func(interface{}) error) error
- func (m *ClientThrift) RpcWithContext(ctx context.Context, hashKey string, timeout time.Duration, ...) error
- func (m *ClientThrift) RpcWithContextV2(ctx context.Context, hashKey string, timeout time.Duration, ...) error
- func (m *ClientThrift) SetConfigCenter(configCenter xconfig.ConfigCenter)
- type ClientWrapper
- func (m *ClientWrapper) Call(ctx context.Context, hashKey, funcName string, run func(addr string) error) error
- func (m *ClientWrapper) Do(hashKey string, timeout time.Duration, ...) error
- func (fs *ClientWrapper) GetFallbackFunc(name string) fallbackFunc
- func (fs *ClientWrapper) RegisterFallbackFunc(name string, fallback fallbackFunc)
- func (m *ClientWrapper) SetConfigCenter(configCenter xconfig.ConfigCenter)
- type Concurrent
- type ConnectionPool
- type Context
- type ErrCode
- type ErrorResponseBody
- type FunInterceptor
- type GrpcServer
- type HandlerFunc
- type Hash
- type HealthCheck
- type HttpRouter
- func (r *HttpRouter) DELETE(path string, handle httprouter.Handle)
- func (r *HttpRouter) GET(path string, handle httprouter.Handle)
- func (r *HttpRouter) HEAD(path string, handle httprouter.Handle)
- func (r *HttpRouter) Handle(method, path string, handle httprouter.Handle)
- func (r *HttpRouter) Handler(method, path string, handler http.Handler)
- func (r *HttpRouter) HandlerFunc(method, path string, handler http.HandlerFunc)
- func (r *HttpRouter) OPTIONS(path string, handle httprouter.Handle)
- func (r *HttpRouter) PATCH(path string, handle httprouter.Handle)
- func (r *HttpRouter) POST(path string, handle httprouter.Handle)
- func (r *HttpRouter) PUT(path string, handle httprouter.Handle)
- func (r *HttpRouter) Use(middlewares ...Middleware)
- type HttpServer
- func (s *HttpServer) Any(relativePath string, handlers ...HandlerFunc)
- func (s *HttpServer) DELETE(relativePath string, handlers ...HandlerFunc)
- func (s *HttpServer) GET(relativePath string, handlers ...HandlerFunc)
- func (s *HttpServer) HEAD(relativePath string, handlers ...HandlerFunc)
- func (s *HttpServer) OPTIONS(relativePath string, handlers ...HandlerFunc)
- func (s *HttpServer) PATCH(relativePath string, handlers ...HandlerFunc)
- func (s *HttpServer) POST(relativePath string, handlers ...HandlerFunc)
- func (s *HttpServer) PUT(relativePath string, handlers ...HandlerFunc)
- func (s *HttpServer) Use(middleware ...HandlerFunc)
- func (s *HttpServer) WAny(relativePath string, handlers ...httprouter.Handle)
- func (s *HttpServer) WDELETE(relativePath string, handlers ...httprouter.Handle)
- func (s *HttpServer) WGET(relativePath string, handlers ...httprouter.Handle)
- func (s *HttpServer) WHEAD(relativePath string, handlers ...httprouter.Handle)
- func (s *HttpServer) WOPTIONS(relativePath string, handlers ...httprouter.Handle)
- func (s *HttpServer) WPATCH(relativePath string, handlers ...httprouter.Handle)
- func (s *HttpServer) WPOST(relativePath string, handlers ...httprouter.Handle)
- func (s *HttpServer) WPUT(relativePath string, handlers ...httprouter.Handle)
- type ItemConf
- type Logger
- type MD5
- type ManualData
- type Middleware
- type Processor
- type Provider
- type RegData
- type ReqHeader
- type Restart
- type Router
- type ServBase
- type ServBaseV2
- func (m *ServBaseV2) ConfigCenter() xconfig.ConfigCenter
- func (m *ServBaseV2) Copyname() string
- func (m *ServBaseV2) IsLocalRunning() bool
- func (m *ServBaseV2) IsStopped() bool
- func (m *ServBaseV2) Lane() string
- func (m *ServBaseV2) Lock(name string) error
- func (m *ServBaseV2) LockGlobal(name string) error
- func (m *ServBaseV2) RegInfos() map[string]string
- func (m *ServBaseV2) Region() string
- func (m *ServBaseV2) RegisterBackDoor(servs map[string]*ServInfo) error
- func (m *ServBaseV2) RegisterCrossDCService(servs map[string]*ServInfo) error
- func (m *ServBaseV2) RegisterMetrics(servs map[string]*ServInfo) error
- func (m *ServBaseV2) RegisterService(servs map[string]*ServInfo) error
- func (m *ServBaseV2) RegisterServiceV1(servs map[string]*ServInfo, crossDC bool) error
- func (m *ServBaseV2) RegisterServiceV2(servs map[string]*ServInfo, dir string, crossDC bool) error
- func (m *ServBaseV2) ServConfig(cfg interface{}) error
- func (m *ServBaseV2) ServIp() string
- func (m *ServBaseV2) Servid() int
- func (m *ServBaseV2) Servname() string
- func (m *ServBaseV2) SetGroupAndDisable(group string, disable bool) error
- func (m *ServBaseV2) SetOnShutdown(onShutdown func())
- func (m *ServBaseV2) Stop()
- func (m *ServBaseV2) Trylock(name string) (bool, error)
- func (m *ServBaseV2) TrylockGlobal(name string) (bool, error)
- func (m *ServBaseV2) Unlock(name string) error
- func (m *ServBaseV2) UnlockGlobal(name string) error
- func (m *ServBaseV2) WithControlLaneInfo(ctx context.Context) context.Context
- type ServCtrl
- type ServInfo
- type ServProtocol
- type Server
- type ServerModel
- type UnaryHandler
- type UnaryServerInfo
- type UnaryServerInterceptor
Constants ¶
const ( PROCESSOR_HTTP = "http" PROCESSOR_THRIFT = "thrift" PROCESSOR_GRPC = "grpc" PROCESSOR_GIN = "gin" )
rpc protocol
const ( HttpHeaderKeyTraceID = "ipalfish-trace-id" WildCharacter = ":" RoutePath = "req-simple-path" HttpHeaderKeyGroup = "ipalfish-group" HttpHeaderKeyHead = "ipalfish-head" CookieNameGroup = "ipalfish_group" ReqHeaderKey = "req_header" )
const ( BASE_LOC_DIST = "dist" // 调整了服务注册结构,为兼容老版本,BASE_LOC_DIST下也要完成之前方式的注册 // dist2 2为版本2 BASE_LOC_DIST_V2 = "dist2" BASE_LOC_BREAKER = "breaker" BASE_LOC_BREAKER_GLOBAL = "breaker/global" BASE_LOC_ETC = "etc" BASE_LOC_ETC_GLOBAL = "etc/global" BASE_LOC_SKEY = "skey" BASE_LOC_OP = "op" BASE_LOC_DB = "db/route" // 服务内分布式锁,只在单个服务副本之间使用 BASE_LOC_LOCAL_DIST_LOCK = "lock/local" // 全局分布式锁,跨服务使用 BASE_LOC_GLOBAL_DIST_LOCK = "lock/global" // thrift 服务注册的位置 BASE_LOC_REG_SERV = "serve" // 后门注册的位置 BASE_LOC_REG_BACKDOOR = "backdoor" // 服务手动配置位置 BASE_LOC_REG_MANUAL = "manual" // sla metrics注册的位置 BASE_LOC_REG_METRICS = "metrics" PROCESSOR_GRPC_PROPERTY_NAME = "proc_grpc" PROCESSOR_THRIFT_PROPERTY_NAME = "proc_thrift" //预演环境分组标识 ENV_GROUP_PRE = "pre" // RPCConfNamespace RPC Apollo Conf Namespace RPCConfNamespace = "rpc.client" RPCServerConfNamespace = "rpc.server" ApplicationNamespace = "application" DefaultEtcdClientTimeout = 3 * time.Second )
const ( TrafficLogID = "TRAFFIC" TrafficLogKeyUID = "uid" TrafficLogKeyGroup = "group" TrafficLogKeyTraceID = "tid" TrafficLogKeySpanID = "sid" TrafficLogKeyParentSpanID = "pid" TrafficLogKeyOperation = "op" TrafficLogKeyCaller = "caller" TrafficLogKeyServerType = "stype" TrafficLogKeyServerID = "srvid" TrafficLogKeyServerName = "sname" )
const ( // Timeout timeout(ms) Timeout = "timeoutMsec" // Retry ... Retry = "retry" // Default ... Default = "Default" )
const ErrCodeKey = "ErrCode"
const START_TYPE_LOCAL = "local"
const (
TTL_LOCK = time.Second * 180
)
const UNSPECIFIED_CALLER = "NULL"
Variables ¶
var (
ErrConnectionPoolClosed = errors.New("connection pool is closed")
)
Functions ¶
func AccessLog ¶ added in v1.7.34
func AccessLog() gin.HandlerFunc
func ContextHeadUnaryClientInterceptor ¶ added in v1.8.26
func ContextHeadUnaryClientInterceptor() grpc.UnaryClientInterceptor
func ContextSetErrCode ¶ added in v1.7.32
func DisableContextCancel ¶ added in v1.8.30
func DisableContextCancel() gin.HandlerFunc
func FactoryHealthCheck ¶ added in v1.0.5
func FactoryHealthCheck() xhttp.HandleRequest
func FactoryRestart ¶
func FactoryRestart() xhttp.HandleRequest
func GetAPIRequestCountMetricV2 ¶ added in v1.7.28
GetAPIRequestCountMetric export api request count metric
func GetAPIRequestTimeMetricV2 ¶ added in v1.7.28
GetAPIRequestTimeMetric export api request time metric
func GetCallerFromBaggage ¶ added in v1.8.24
从trace中获取baggage上游服务
func GetConfigCenter ¶ added in v1.5.0
func GetConfigCenter() xconfig.ConfigCenter
GetConfigCenter get serv conf center
func GetDBRequestCountMetric ¶ added in v1.3.9
GetDBRequestCountMetric export db request count metric
func GetDBRequestTimeMetric ¶ added in v1.3.9
GetDBRequestTimeMetric export db request time metric
func GetFuncName ¶ added in v1.4.0
deprecated GetFuncName get func name form runtime info
func GetFuncNameWithCtx ¶ added in v1.5.0
GetFuncNameWithCtx get fun name from context, if not set then use runtime caller
func GetFuncRetry ¶ added in v1.5.0
GetFuncRetry get func retry conf Deprecated: use `GetFuncRetry` method from `ClientGrpc`, `ClientThrift` and `ClientWrapper` instead.
func GetFuncRetryInner ¶ added in v1.8.26
func GetFuncRetryInner(confCenter xconfig.ConfigCenter, servKey, funcName string) int
GetFuncRetryInner get configured retry times when invoking servKey/funcName.
func GetFuncTimeout ¶ added in v1.5.0
GetFuncTimeout get func timeout conf Deprecated: use `GetFuncTimeout` method from `ClientGrpc`, `ClientThrift` and `ClientWrapper` instead.
func GetFuncTimeoutInner ¶ added in v1.8.26
func GetFuncTimeoutInner(confCenter xconfig.ConfigCenter, servKey, funcName string, defaultTime time.Duration) time.Duration
GetFuncTimeoutInner get configured timout when invoking servKey/funcName. `defaultTime` will be returned if it's not configured
func GetGroupAndService ¶ added in v1.3.7
func GetGroupAndService() (group, service string)
GetGroupAndService return group and service name of this service
func GetInterfaceRateLimitRegistry ¶ added in v1.6.0
func GetInterfaceRateLimitRegistry() registry.InterfaceRateLimitRegistry
获取接口限流的 registry 管理对象。 thrift 服务,无法直接在 roc 里面统一搞定限流。暴露这个函数,以供 codegen 使用。
func GetLogCountMetric ¶ added in v1.3.9
GetLogCountMetric export log request count metric
func GetProcessorAddress ¶ added in v1.5.7
GetAddress get processor ip+port by processorName
func GetServName ¶ added in v1.2.0
func GetServName() (servName string)
func GetSlaDurationMetric ¶ added in v1.2.20
func GetSlaRequestTotalMetric ¶ added in v1.2.20
func Init ¶
func Init(etcdAddrs []string, baseLoc string, servLoc, servKey, logDir string, initLogic func(ServBase) error, processors map[string]Processor) error
Init use in test of application Deprecated, use Test instead
func InjectFromRequest ¶ added in v1.7.17
func InjectFromRequest() gin.HandlerFunc
func LaneInfoUnaryClientInterceptor ¶ added in v1.7.22
func LaneInfoUnaryClientInterceptor() grpc.UnaryClientInterceptor
func MasterSlave ¶ added in v1.2.7
func MasterSlave(etcdAddrs []string, baseLoc string, initLogic func(ServBase) error, processors map[string]Processor) error
MasterSlave Leader-Follower模式,通过etcd distribute lock进行选举
func NewGinServer ¶ added in v1.8.30
func NotFound ¶ added in v1.8.25
func NotFound() gin.HandlerFunc
NotFound NotFound returns a 404 not found handle
func ParseUriApi ¶ added in v1.8.21
func RateLimit ¶ added in v1.8.30
func RateLimit() gin.HandlerFunc
func Recovery ¶ added in v1.5.7
func Recovery() gin.HandlerFunc
Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.
func Serve ¶
func Serve(etcdAddrs []string, baseLoc string, initLogic func(ServBase) error, processors map[string]Processor) error
Serve app call Serve to start server, initLogic is the init func in app, logic.InitLogic,
func ServeForTest ¶ added in v1.7.19
func ServeForTest(etcdAddrs []string, baseLoc, servLoc string, initLogic func(ServBase) error) error
用于测试时启动框架, 功能同Test(), 但启动完成后不会阻塞
Types ¶
type Addr ¶ added in v1.2.12
type Addr struct {
// contains filtered or unexported fields
}
func NewAddr ¶ added in v1.2.12
func NewAddr(cb ClientLookup) *Addr
type BaseConfig ¶ added in v1.3.10
type BaseConfig struct {
Base struct {
CrossRegisterCenters []string `sep:"," sconf:"crossRegisterCenters"`
}
}
BaseConfig 基础配置
type Breaker ¶
type Breaker struct {
// contains filtered or unexported fields
}
func NewBreaker ¶
func NewBreaker(clientLookup ClientLookup) *Breaker
type BreakerStat ¶ added in v1.1.0
type BreakerStat struct {
// contains filtered or unexported fields
}
type ClientEtcdV2 ¶
type ClientEtcdV2 struct {
// contains filtered or unexported fields
}
func NewClientEtcdV2 ¶
func NewClientEtcdV2(confEtcd configEtcd, servlocation string) (*ClientEtcdV2, error)
func NewClientLookup ¶
func NewClientLookup(etcdaddrs []string, baseLoc string, servlocation string) (*ClientEtcdV2, error)
func (*ClientEtcdV2) GetAllServAddr ¶ added in v1.1.0
func (m *ClientEtcdV2) GetAllServAddr(processor string) []*ServInfo
func (*ClientEtcdV2) GetAllServAddrWithGroup ¶ added in v1.2.0
func (m *ClientEtcdV2) GetAllServAddrWithGroup(group, processor string) []*ServInfo
func (*ClientEtcdV2) GetServAddr ¶
func (m *ClientEtcdV2) GetServAddr(processor, key string) *ServInfo
func (*ClientEtcdV2) GetServAddrWithGroup ¶ added in v1.2.0
func (m *ClientEtcdV2) GetServAddrWithGroup(group string, processor, key string) *ServInfo
func (*ClientEtcdV2) GetServAddrWithServid ¶
func (m *ClientEtcdV2) GetServAddrWithServid(servid int, processor, key string) *ServInfo
func (*ClientEtcdV2) RegisterDeleteAddrHandler ¶ added in v1.7.30
func (m *ClientEtcdV2) RegisterDeleteAddrHandler(handle deleteAddrHandler)
func (*ClientEtcdV2) ServKey ¶
func (m *ClientEtcdV2) ServKey() string
func (*ClientEtcdV2) ServPath ¶
func (m *ClientEtcdV2) ServPath() string
func (*ClientEtcdV2) String ¶ added in v1.4.1
func (m *ClientEtcdV2) String() string
type ClientGrpc ¶ added in v1.1.0
type ClientGrpc struct {
// contains filtered or unexported fields
}
ClientGrpc client of grpc in adapter
func NewClientGrpc ¶ added in v1.1.0
func NewClientGrpc(cb ClientLookup, processor string, capacity int, fn func(client *grpc.ClientConn) interface{}) *ClientGrpc
func NewClientGrpcByConcurrentRouter ¶ added in v1.1.0
func NewClientGrpcByConcurrentRouter(cb ClientLookup, processor string, capacity int, fn func(client *grpc.ClientConn) interface{}) *ClientGrpc
func NewClientGrpcWithRouterType ¶ added in v1.1.0
func NewClientGrpcWithRouterType(cb ClientLookup, processor string, capacity int, fn func(client *grpc.ClientConn) interface{}, routerType int) *ClientGrpc
NewClientGrpcWithRouterType create grpc client by routerType, fn: xxServiceClient of xx, such as NewChangeBoardServiceClient
func (*ClientGrpc) CustomizedRouteRpc ¶ added in v1.1.0
func (m *ClientGrpc) CustomizedRouteRpc(getProvider func() *Provider, fnrpc func(interface{}) error) error
func (*ClientGrpc) DirectRouteRpc ¶ added in v1.1.0
func (m *ClientGrpc) DirectRouteRpc(provider *Provider, fnrpc func(interface{}) error) error
func (*ClientGrpc) GetFallbackFunc ¶ added in v1.6.0
func (fs *ClientGrpc) GetFallbackFunc(name string) fallbackFunc
`nil` will be returned if no fallback func is registered.
func (*ClientGrpc) RegisterFallbackFunc ¶ added in v1.6.0
func (fs *ClientGrpc) RegisterFallbackFunc(name string, fallback fallbackFunc)
func (*ClientGrpc) Rpc ¶ added in v1.1.0
func (m *ClientGrpc) Rpc(hashKey string, fnrpc func(interface{}) error) error
deprecated
func (*ClientGrpc) RpcWithContext ¶ added in v1.2.0
func (*ClientGrpc) RpcWithContextV2 ¶ added in v1.2.13
func (*ClientGrpc) SetConfigCenter ¶ added in v1.8.26
func (m *ClientGrpc) SetConfigCenter(configCenter xconfig.ConfigCenter)
type ClientLookup ¶
type ClientLookup interface {
GetServAddr(processor, key string) *ServInfo
GetServAddrWithServid(servid int, processor, key string) *ServInfo
GetServAddrWithGroup(group string, processor, key string) *ServInfo
GetAllServAddr(processor string) []*ServInfo
GetAllServAddrWithGroup(group, processor string) []*ServInfo
ServKey() string
ServPath() string
RegisterDeleteAddrHandler(deleteAddrHandler)
}
type ClientPool ¶ added in v1.1.0
type ClientPool struct {
// contains filtered or unexported fields
}
ClientPool every addr has a connection pool, each backend server has more than one addr, in client side, it's ClientPool
func NewClientPool ¶ added in v1.1.0
func NewClientPool(idle, active int, rpcFactory func(addr string) (rpcClientConn, error), calleeServiceKey string) *ClientPool
NewClientPool constructor of pool, 如果连接数过低,修正为默认值
func (*ClientPool) Close ¶ added in v1.4.0
func (m *ClientPool) Close()
Close close connection pool in client pool
func (*ClientPool) Get ¶ added in v1.2.0
func (m *ClientPool) Get(ctx context.Context, addr string) (rpcClientConn, error)
Get get connection from pool, if reach max, create new connection and return
func (*ClientPool) Put ¶ added in v1.1.0
func (m *ClientPool) Put(addr string, client rpcClientConn, err error)
Put 连接池回收连接
type ClientThrift ¶
type ClientThrift struct {
// contains filtered or unexported fields
}
ClientThrift client of thrift in adapter
func NewClientThrift ¶
func NewClientThrift(cb ClientLookup, processor string, fn func(thrift.TTransport, thrift.TProtocolFactory) interface{}, capacity int) *ClientThrift
func NewClientThriftByAddrRouter ¶ added in v1.2.12
func NewClientThriftByAddrRouter(cb ClientLookup, processor string, fn func(thrift.TTransport, thrift.TProtocolFactory) interface{}, capacity int) *ClientThrift
func NewClientThriftByConcurrentRouter ¶ added in v1.1.0
func NewClientThriftByConcurrentRouter(cb ClientLookup, processor string, fn func(thrift.TTransport, thrift.TProtocolFactory) interface{}, capacity int) *ClientThrift
func NewClientThriftWithRouterType ¶ added in v1.1.0
func NewClientThriftWithRouterType(cb ClientLookup, processor string, fn func(thrift.TTransport, thrift.TProtocolFactory) interface{}, capacity, routerType int) *ClientThrift
NewClientThriftWithRouterType create thrift client with router type, fn: xxServiceClientFactory, such as NewServmgrServiceClientFactory
func (*ClientThrift) GetFallbackFunc ¶ added in v1.6.0
func (fs *ClientThrift) GetFallbackFunc(name string) fallbackFunc
`nil` will be returned if no fallback func is registered.
func (*ClientThrift) RegisterFallbackFunc ¶ added in v1.6.0
func (fs *ClientThrift) RegisterFallbackFunc(name string, fallback fallbackFunc)
func (*ClientThrift) Rpc ¶
func (m *ClientThrift) Rpc(hashKey string, timeout time.Duration, fnrpc func(interface{}) error) error
deprecated
func (*ClientThrift) RpcWithContext ¶ added in v1.2.0
func (m *ClientThrift) RpcWithContext(ctx context.Context, hashKey string, timeout time.Duration, fnrpc func(interface{}) error) error
deprecated
func (*ClientThrift) RpcWithContextV2 ¶ added in v1.2.13
func (*ClientThrift) SetConfigCenter ¶ added in v1.8.26
func (m *ClientThrift) SetConfigCenter(configCenter xconfig.ConfigCenter)
type ClientWrapper ¶
type ClientWrapper struct {
// contains filtered or unexported fields
}
ClientWrapper 目前网关通过common/go/pub在使用
func NewClientWrapper ¶
func NewClientWrapper(cb ClientLookup, processor string) *ClientWrapper
func NewClientWrapperByConcurrentRouter ¶ added in v1.1.0
func NewClientWrapperByConcurrentRouter(cb ClientLookup, processor string) *ClientWrapper
func NewClientWrapperWithRouterType ¶ added in v1.1.0
func NewClientWrapperWithRouterType(cb ClientLookup, processor string, routerType int) *ClientWrapper
func (*ClientWrapper) GetFallbackFunc ¶ added in v1.6.0
func (fs *ClientWrapper) GetFallbackFunc(name string) fallbackFunc
`nil` will be returned if no fallback func is registered.
func (*ClientWrapper) RegisterFallbackFunc ¶ added in v1.6.0
func (fs *ClientWrapper) RegisterFallbackFunc(name string, fallback fallbackFunc)
func (*ClientWrapper) SetConfigCenter ¶ added in v1.8.26
func (m *ClientWrapper) SetConfigCenter(configCenter xconfig.ConfigCenter)
type Concurrent ¶ added in v1.1.0
type Concurrent struct {
// contains filtered or unexported fields
}
func NewConcurrent ¶ added in v1.1.0
func NewConcurrent(cb ClientLookup) *Concurrent
func (*Concurrent) Post ¶ added in v1.1.0
func (m *Concurrent) Post(s *ServInfo) error
func (*Concurrent) Pre ¶ added in v1.1.0
func (m *Concurrent) Pre(s *ServInfo) error
type ConnectionPool ¶ added in v1.4.0
type ConnectionPool struct {
// contains filtered or unexported fields
}
ConnectionPool connection pool corresponding to the addr
func NewConnectionPool ¶ added in v1.4.0
func NewConnectionPool(addr string, idle, active int, idleTimeout time.Duration, rpcFactory func(addr string) (rpcClientConn, error), calleeServiceKey string) *ConnectionPool
NewConnectionPool constructor of ConnectionPool
func (*ConnectionPool) Addr ¶ added in v1.4.0
func (cp *ConnectionPool) Addr() string
Addr return addr of connection pool
func (*ConnectionPool) Close ¶ added in v1.4.0
func (cp *ConnectionPool) Close()
Close close connection pool
func (*ConnectionPool) Get ¶ added in v1.4.0
func (cp *ConnectionPool) Get(ctx context.Context) (rpcClientConn, error)
Get return a connection, you should call PooledConnection's Recycle once done
func (*ConnectionPool) Open ¶ added in v1.4.0
func (cp *ConnectionPool) Open()
func (*ConnectionPool) Put ¶ added in v1.4.0
func (cp *ConnectionPool) Put(conn rpcClientConn, forceClose bool)
Put recycle a connection into the pool
type ErrorResponseBody ¶ added in v1.8.25
type ErrorResponseBody struct {
Ret int32 `json:"ret"`
Code int32 `json:"code"`
Msg string `json:"msg"`
}
ErrorResponseBody HTTP 层出错时的标准响应。
type FunInterceptor ¶ added in v1.1.0
type GrpcServer ¶ added in v1.1.0
func NewGrpcServer ¶ added in v1.1.0
func NewGrpcServer(fns ...FunInterceptor) *GrpcServer
Deprecated NewGrpcServer create grpc server with interceptors before handler
func NewGrpcServerWithUnaryInterceptors ¶ added in v1.6.5
func NewGrpcServerWithUnaryInterceptors(interceptors ...UnaryServerInterceptor) *GrpcServer
NewGrpcServerWithUnaryInterceptors 创建GrpcServer并添加自定义Unary拦截器 拦截器的调用顺序与添加顺序前向相同, 后向相反. 即如果添加顺序为: a, b. 则调用链顺序为: pre-a -> pre-b -> grpc_func() -> post-b -> post-a 这里添加的是用户自定义拦截器, 会添加在系统内置拦截器之后 (如tracing, 熔断等). 示例 (对应于你的service项目中的processor/proc_grpc.go文件)
func (m *ProcGrpc) Driver() (string, interface{}) {
monitorInterceptor := func(ctx context.Context, req interface{}, info *rocserv.UnaryServerInfo, handler rocserv.UnaryHandler) (interface{}, error) {
// 这里添加接口调用前的拦截器处理逻辑
// e.g. 统计接口请求耗时
st := xtime.NewTimeStat()
defer func() {
dur := st.Duration()
xlog.Infof(ctx, "monitor example, func: %s, req: %v, ctx: %v, duration: %v", info.FullMethod, req, ctx, dur)
}()
// gRPC接口调用 (固定写法)
ret, err := handler(ctx, req)
// 这里添加接口调用后的拦截器处理逻辑
// e.g. 接口调用出错时打error日志
if err != nil {
xlog.Warnf(ctx, "call grpc error, func: %s, req: %v, err: %v", info.FullMethod, req, err)
}
return ret, err
}
serv := rocserv.NewGrpcServerWithInterceptors(monitorInterceptor)
RegisterChangeBoardServiceServer(serv.Server, new(GrpcChangeBoardServiceImpl))
// 使用随机端口
return "", serv
}
type HandlerFunc ¶ added in v1.5.7
type HandlerFunc func(*Context)
HandlerFunc ...
func MutilWrapHttpRouter ¶ added in v1.5.7
func MutilWrapHttpRouter(handlers ...httprouter.Handle) []HandlerFunc
MutilWrapHttpRouter wrap many httprouter handle to roc httpserver handle
func WrapHttpRouter ¶ added in v1.5.7
func WrapHttpRouter(handle httprouter.Handle) HandlerFunc
WrapHttpRouter wrap httprouter handle to roc httpserver handle
type Hash ¶ added in v1.1.0
type Hash struct {
// contains filtered or unexported fields
}
func NewHash ¶ added in v1.1.0
func NewHash(cb ClientLookup) *Hash
type HealthCheck ¶ added in v1.0.5
type HealthCheck struct {
}
==============================
func (*HealthCheck) Handle ¶ added in v1.0.5
func (m *HealthCheck) Handle(r *xhttp.HttpRequest) xhttp.HttpResponse
type HttpRouter ¶ added in v1.8.30
type HttpRouter struct {
*httprouter.Router
// contains filtered or unexported fields
}
func NewHttpRouter ¶ added in v1.8.30
func NewHttpRouter() *HttpRouter
NewHttpRouter returns a new initialized Router. Supported trace, metric and custom middlewares
func (*HttpRouter) DELETE ¶ added in v1.8.30
func (r *HttpRouter) DELETE(path string, handle httprouter.Handle)
DELETE is a shortcut for router.Handle(http.MethodDelete, path, handle)
func (*HttpRouter) GET ¶ added in v1.8.30
func (r *HttpRouter) GET(path string, handle httprouter.Handle)
GET is a shortcut for router.Handle(http.MethodGet, path, handle)
func (*HttpRouter) HEAD ¶ added in v1.8.30
func (r *HttpRouter) HEAD(path string, handle httprouter.Handle)
HEAD is a shortcut for router.Handle(http.MethodHead, path, handle)
func (*HttpRouter) Handle ¶ added in v1.8.30
func (r *HttpRouter) Handle(method, path string, handle httprouter.Handle)
Handle registers a new request handle with the given path and method.
For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.
This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).
func (*HttpRouter) Handler ¶ added in v1.8.30
func (r *HttpRouter) Handler(method, path string, handler http.Handler)
Handler is an adapter which allows the usage of an http.Handler as a request handle. The Params are available in the request context under ParamsKey.
func (*HttpRouter) HandlerFunc ¶ added in v1.8.30
func (r *HttpRouter) HandlerFunc(method, path string, handler http.HandlerFunc)
HandlerFunc is an adapter which allows the usage of an http.HandlerFunc as a request handle.
func (*HttpRouter) OPTIONS ¶ added in v1.8.30
func (r *HttpRouter) OPTIONS(path string, handle httprouter.Handle)
OPTIONS is a shortcut for router.Handle(http.MethodOptions, path, handle)
func (*HttpRouter) PATCH ¶ added in v1.8.30
func (r *HttpRouter) PATCH(path string, handle httprouter.Handle)
PATCH is a shortcut for router.Handle(http.MethodPatch, path, handle)
func (*HttpRouter) POST ¶ added in v1.8.30
func (r *HttpRouter) POST(path string, handle httprouter.Handle)
POST is a shortcut for router.Handle(http.MethodPost, path, handle)
func (*HttpRouter) PUT ¶ added in v1.8.30
func (r *HttpRouter) PUT(path string, handle httprouter.Handle)
PUT is a shortcut for router.Handle(http.MethodPut, path, handle)
func (*HttpRouter) Use ¶ added in v1.8.30
func (r *HttpRouter) Use(middlewares ...Middleware)
Use attaches global middlewares to the router
type HttpServer ¶ added in v1.5.7
HttpServer is the http server, Create an instance of GinServer, by using NewGinServer()
func NewHttpServer ¶ added in v1.5.7
func NewHttpServer() *HttpServer
NewHttpServer create http server with gin
func (*HttpServer) Any ¶ added in v1.5.7
func (s *HttpServer) Any(relativePath string, handlers ...HandlerFunc)
Any registers a route that matches all the HTTP methods.
func (*HttpServer) DELETE ¶ added in v1.5.7
func (s *HttpServer) DELETE(relativePath string, handlers ...HandlerFunc)
DELETE is a shortcut for router.Handle("DELETE", path, handle).
func (*HttpServer) GET ¶ added in v1.5.7
func (s *HttpServer) GET(relativePath string, handlers ...HandlerFunc)
GET is a shortcut for router.Handle("GET", path, handle).
func (*HttpServer) HEAD ¶ added in v1.5.7
func (s *HttpServer) HEAD(relativePath string, handlers ...HandlerFunc)
HEAD is a shortcut for router.Handle("HEAD", path, handle).
func (*HttpServer) OPTIONS ¶ added in v1.5.7
func (s *HttpServer) OPTIONS(relativePath string, handlers ...HandlerFunc)
OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle).
func (*HttpServer) PATCH ¶ added in v1.5.7
func (s *HttpServer) PATCH(relativePath string, handlers ...HandlerFunc)
PATCH is a shortcut for router.Handle("PATCH", path, handle).
func (*HttpServer) POST ¶ added in v1.5.7
func (s *HttpServer) POST(relativePath string, handlers ...HandlerFunc)
POST is a shortcut for router.Handle("POST", path, handle).
func (*HttpServer) PUT ¶ added in v1.5.7
func (s *HttpServer) PUT(relativePath string, handlers ...HandlerFunc)
PUT is a shortcut for router.Handle("PUT", path, handle).
func (*HttpServer) Use ¶ added in v1.5.7
func (s *HttpServer) Use(middleware ...HandlerFunc)
Use attachs a global middleware to the router
func (*HttpServer) WAny ¶ added in v1.5.7
func (s *HttpServer) WAny(relativePath string, handlers ...httprouter.Handle)
WAny is wrap httprouter handle to ANY
func (*HttpServer) WDELETE ¶ added in v1.5.7
func (s *HttpServer) WDELETE(relativePath string, handlers ...httprouter.Handle)
WDELETE is wrap httprouter handle to DELETE
func (*HttpServer) WGET ¶ added in v1.5.7
func (s *HttpServer) WGET(relativePath string, handlers ...httprouter.Handle)
WGET is wrap httprouter handle to GET
func (*HttpServer) WHEAD ¶ added in v1.5.7
func (s *HttpServer) WHEAD(relativePath string, handlers ...httprouter.Handle)
WHEAD is wrap httprouter handle to HEAD
func (*HttpServer) WOPTIONS ¶ added in v1.5.7
func (s *HttpServer) WOPTIONS(relativePath string, handlers ...httprouter.Handle)
WOPTIONS is wrap httprouter handle to OPTIONS
func (*HttpServer) WPATCH ¶ added in v1.5.7
func (s *HttpServer) WPATCH(relativePath string, handlers ...httprouter.Handle)
WPATCH is wrap httprouter handle to PATCH
func (*HttpServer) WPOST ¶ added in v1.5.7
func (s *HttpServer) WPOST(relativePath string, handlers ...httprouter.Handle)
WPOST is wrap httprouter handle to POST
func (*HttpServer) WPUT ¶ added in v1.5.7
func (s *HttpServer) WPUT(relativePath string, handlers ...httprouter.Handle)
WPUT is wrap httprouter handle to PUT
type MD5 ¶ added in v1.2.29
type MD5 struct {
}
MD5 ...
func (*MD5) Handle ¶ added in v1.2.29
func (m *MD5) Handle(r *xhttp.HttpRequest) xhttp.HttpResponse
type ManualData ¶
type ManualData struct {
Ctrl *ServCtrl `json:"ctrl"`
}
type Middleware ¶ added in v1.8.30
type Middleware func(httprouter.Handle) httprouter.Handle
func DisableContextCancelForHttpRouter ¶ added in v1.8.30
func DisableContextCancelForHttpRouter() Middleware
func MetricForHttpRouter ¶ added in v1.8.30
func MetricForHttpRouter() Middleware
func TraceForHttpRouter ¶ added in v1.8.30
func TraceForHttpRouter() Middleware
type ReqHeader ¶ added in v1.8.26
type ReqHeader struct {
Token string `json:"token"`
Uid int64 `json:"h_m"`
Did string `json:"h_did"`
Ver string `json:"h_av"`
Model string `json:"h_model"` // 设备型号
Dt int32 `json:"h_dt"`
Dtsub int32 `json:"h_dt_sub"`
Ch string `json:"h_ch"`
Net int32 `json:"h_nt"`
Unionid string `json:"h_unionid"`
Het int32 `json:"h_et"` // 终端类型,0其他;1APP;2web或H5;3微信;4小程序
HLc string `json:"h_lc"`
Cate int32 `json:"cate"`
Source int32 `json:"h_src"`
Zone int32 `json:"zone"`
Subsource int32 `json:"h_sub_src"`
ZoneName string `json:"zone_name"`
}
ReqHeader 请求规范中,在请求参数中统一包装的一些内容,参考:http://midplatform.book.pri.ibanyu.com/doc/standard/interface.html
type Restart ¶
type Restart struct {
}
==============================
func (*Restart) Handle ¶
func (m *Restart) Handle(r *xhttp.HttpRequest) xhttp.HttpResponse
type Router ¶ added in v1.1.0
type Router interface {
Route(ctx context.Context, processor, key string) *ServInfo
Pre(s *ServInfo) error
Post(s *ServInfo) error
}
Router router include consistent hash、load of concurrent、concrete addr
func NewRouter ¶ added in v1.1.0
func NewRouter(routerType int, cb ClientLookup) Router
type ServBase ¶
type ServBase interface {
// key is processor to ServInfo
RegisterService(servs map[string]*ServInfo) error
RegisterBackDoor(servs map[string]*ServInfo) error
RegisterCrossDCService(servs map[string]*ServInfo) error
Servname() string
ServIp() string
Servid() int
Lane() string
Region() string
// 服务副本名称, servename + servid
Copyname() string
// 获取服务的配置
ServConfig(cfg interface{}) error
// 获取到lock立即返回,否则block直到获取到
Lock(name string) error
// 没有lock的情况下unlock,程序会直接panic
Unlock(name string) error
// 立即返回,如果获取到lock返回true,否则返回false
Trylock(name string) (bool, error)
LockGlobal(name string) error
UnlockGlobal(name string) error
TrylockGlobal(name string) (bool, error)
// conf center
ConfigCenter() xconfig.ConfigCenter
// reginfos
RegInfos() map[string]string
// stop
Stop()
// set app shutdown hook
SetOnShutdown(func())
// return true if server is local running
IsLocalRunning() bool
// wrap context with service context info, such as lane
WithControlLaneInfo(ctx context.Context) context.Context
// is stopped
IsStopped() bool
}
ServBase Interface
func GetServBase ¶ added in v1.2.0
func GetServBase() ServBase
type ServBaseV2 ¶
type ServBaseV2 struct {
// contains filtered or unexported fields
}
func (*ServBaseV2) ConfigCenter ¶ added in v1.5.0
func (m *ServBaseV2) ConfigCenter() xconfig.ConfigCenter
ConfigCenter ...
func (*ServBaseV2) Copyname ¶
func (m *ServBaseV2) Copyname() string
func (*ServBaseV2) IsLocalRunning ¶ added in v1.7.11
func (m *ServBaseV2) IsLocalRunning() bool
func (*ServBaseV2) IsStopped ¶ added in v1.7.14
func (m *ServBaseV2) IsStopped() bool
func (*ServBaseV2) Lane ¶ added in v1.7.12
func (m *ServBaseV2) Lane() string
func (*ServBaseV2) Lock ¶
func (m *ServBaseV2) Lock(name string) error
func (*ServBaseV2) LockGlobal ¶
func (m *ServBaseV2) LockGlobal(name string) error
func (*ServBaseV2) RegInfos ¶ added in v1.5.7
func (m *ServBaseV2) RegInfos() map[string]string
RegInfos ...
func (*ServBaseV2) Region ¶ added in v1.7.12
func (m *ServBaseV2) Region() string
func (*ServBaseV2) RegisterBackDoor ¶
func (m *ServBaseV2) RegisterBackDoor(servs map[string]*ServInfo) error
func (*ServBaseV2) RegisterCrossDCService ¶ added in v1.3.10
func (m *ServBaseV2) RegisterCrossDCService(servs map[string]*ServInfo) error
RegisterCrossDCService, the path and value is the same as RegisterService, but different register center
func (*ServBaseV2) RegisterMetrics ¶ added in v1.1.0
func (m *ServBaseV2) RegisterMetrics(servs map[string]*ServInfo) error
func (*ServBaseV2) RegisterService ¶
func (m *ServBaseV2) RegisterService(servs map[string]*ServInfo) error
{type:http/thrift, addr:10.3.3.3:23233, processor:fuck}
func (*ServBaseV2) RegisterServiceV1 ¶
func (m *ServBaseV2) RegisterServiceV1(servs map[string]*ServInfo, crossDC bool) error
为兼容老的client发现服务,保留的
func (*ServBaseV2) RegisterServiceV2 ¶
func (*ServBaseV2) ServConfig ¶
func (m *ServBaseV2) ServConfig(cfg interface{}) error
func (*ServBaseV2) ServIp ¶ added in v1.6.2
func (m *ServBaseV2) ServIp() string
func (*ServBaseV2) Servid ¶
func (m *ServBaseV2) Servid() int
func (*ServBaseV2) Servname ¶
func (m *ServBaseV2) Servname() string
func (*ServBaseV2) SetGroupAndDisable ¶ added in v1.2.6
func (m *ServBaseV2) SetGroupAndDisable(group string, disable bool) error
func (*ServBaseV2) SetOnShutdown ¶ added in v1.5.14
func (m *ServBaseV2) SetOnShutdown(onShutdown func())
SetOnShutdown add shutdown hook in app
func (*ServBaseV2) TrylockGlobal ¶
func (m *ServBaseV2) TrylockGlobal(name string) (bool, error)
func (*ServBaseV2) Unlock ¶
func (m *ServBaseV2) Unlock(name string) error
func (*ServBaseV2) UnlockGlobal ¶
func (m *ServBaseV2) UnlockGlobal(name string) error
func (*ServBaseV2) WithControlLaneInfo ¶ added in v1.6.8
func (m *ServBaseV2) WithControlLaneInfo(ctx context.Context) context.Context
type ServProtocol ¶ added in v1.1.0
type ServProtocol int
const ( GRPC ServProtocol = iota THRIFT HTTP LaneInfoMetadataKey = "ipalfish-lane-info" BaggageCallerKey = "ipalfish-roc-caller" )
type Server ¶ added in v1.4.0
type Server struct {
// contains filtered or unexported fields
}
Server ...
type ServerModel ¶ added in v1.8.26
type ServerModel int
server model
const ( MODEL_SERVER ServerModel = 0 MODEL_MASTERSLAVE ServerModel = 1 )
type UnaryHandler ¶ added in v1.6.5
UnaryHandler是grpc UnaryHandler的别名, 便于统一管理grpc升级
type UnaryServerInfo ¶ added in v1.6.5
type UnaryServerInfo struct {
// Server is the service implementation the user provides. This is read-only.
Server interface{}
// FullMethod is the full RPC method string, i.e., /package.service/method.
FullMethod string
}
UnaryServerInfo是grpc UnaryServerInfo的别名, 便于统一管理grpc升级
type UnaryServerInterceptor ¶ added in v1.6.5
type UnaryServerInterceptor func(ctx context.Context, req interface{}, info *UnaryServerInfo, handler UnaryHandler) (interface{}, error)
UnaryServerInterceptor是grpc UnaryServerInterceptor的别名, 便于统一管理grpc升级
Source Files
¶
- admin.go
- breaker.go
- client_grpc.go
- client_http.go
- client_pool.go
- client_thrift.go
- config.go
- conn_pool.go
- cross_dc_register.go
- distributed_lock.go
- metrics.go
- power.go
- processor_interface.go
- rate_limiter.go
- registry.go
- registry_interface.go
- router.go
- server.go
- server_grpc.go
- server_http.go
- service.go
- service_interface.go
- traffic.go
- util.go