Documentation ¶
Overview ¶
Package gokit
Package gokit microservice implemented by gokit @Author Ryan Fan 2021-07-27 @Update Ryan Fan 2021-07-27
Index ¶
- Constants
- Variables
- func NewMicroService(logger types.LogProvider, config *MicroServiceConfig) (types.MicroService, error)
- type BaseGokitClient
- type BaseServerManager
- type CircuitBreakConfig
- type ClientConfig
- type GokitGrpcServerManager
- type GokitHttpServer
- type GokitProvider
- type GokitProviderConfig
- type GrpcClientManager
- type InjectFunction
- type MicroServiceConfig
- type MicroServiceImpl
- func (msi MicroServiceImpl) GetClientConfig(transport string) *ClientConfig
- func (msi MicroServiceImpl) GetServerConfig(transport string) *ServerConfig
- func (msi MicroServiceImpl) NewGrpcClientManager() types.GrpcClientManager
- func (msi MicroServiceImpl) NewGrpcServerManager() types.GrpcServerManager
- func (msi MicroServiceImpl) NewHttpServerManager() types.HttpServerManager
- type MsMiddleware
- type NewMiddlewareFunc
- type RateLimitConfig
- type ServerConfig
- type TraceConfig
- type Tracer
Constants ¶
const ( MDW_TRACER = "trace" MDW_CIRCUITBREAK = "circuitbreak" MDW_RATELIMIT = "ratelimit" )
const ( GRPC = "grpc" HTTP = "http" )
transport type
Variables ¶
var (
ErrInvalidTraceConfig = errors.New("invalid trace config")
)
var ( NewMdwFunctions = map[string]NewMiddlewareFunc{ MDW_TRACER: NewMdwTrace, MDW_CIRCUITBREAK: NewMdwCircuitBreak, MDW_RATELIMIT: NewMdwRateLimit, } )
Functions ¶
func NewMicroService ¶
func NewMicroService(logger types.LogProvider, config *MicroServiceConfig) (types.MicroService, error)
Types ¶
type BaseGokitClient ¶
type BaseGokitClient struct { Logger types.LogProvider Config *ClientConfig Middlewares []*MsMiddleware }
type BaseServerManager ¶
type BaseServerManager struct { Name string Config *ServerConfig Logger types.LogProvider Middlewares []*MsMiddleware // contains filtered or unexported fields }
type CircuitBreakConfig ¶
type CircuitBreakConfig struct { MaxRequests uint32 `mapstructure:"max"` // 半开后最大允许通过的请求,如果最大请求为0,熔断器值允许一个请求通过 Interval int `mapstructure:"interval"` // 熔断器在关闭状态周期清除内部计数器的间隔,如果为0,则在关闭状态不清除计数器 Timeout int `mapstructure:"timeout"` // 在熔断器半开后进入开放状态的时间,如果为0,则默认设置为60秒 Requests uint32 `mapstructure:"requests"` // 连续请求数量 FailureRatio float64 `mapstructure:"failure_ratio"` // 请求失败率 }
CircuitBreakConfig 服务熔断配置
type ClientConfig ¶
type ClientConfig struct { Transport string `mapstructure:"transport"` Address string `mapstructure:"address"` Middlewares []string `mapstructure:"middlewares"` }
ClientConfig 客户端配置
type GokitGrpcServerManager ¶
type GokitGrpcServerManager struct { BaseServerManager Options []kitgrpc.ServerOption // contains filtered or unexported fields }
func (*GokitGrpcServerManager) CreateHandler ¶
func (s *GokitGrpcServerManager) CreateHandler(concreteService interface{}, ep types.GrpcAspect) *kitgrpc.Server
CreateHandler 创建Grpc Transport的handler
func (*GokitGrpcServerManager) GetServer ¶
func (s *GokitGrpcServerManager) GetServer() *grpc.Server
func (*GokitGrpcServerManager) RunServer ¶
func (s *GokitGrpcServerManager) RunServer() error
RunServer 运行GrpcServer
type GokitHttpServer ¶
type GokitHttpServer struct { BaseServerManager Options []kithttp.ServerOption }
func (*GokitHttpServer) CreateHandler ¶
func (s *GokitHttpServer) CreateHandler(concreteService interface{}, ap types.HttpAspect) http.Handler
CreateHandler 创建Http Transport的Handler
type GokitProvider ¶
type GokitProvider struct {
ms.BaseMsProvider
}
func (*GokitProvider) Init ¶
func (gp *GokitProvider) Init(rootConfiger types.Configer, logger types.LogProvider, args ...interface{}) error
Init implements types.Provider interface, used to initialize the capability @author Ryan Fan (2021-06-09) @param types.Configer root config interface to extract config info @return error
type GokitProviderConfig ¶
type GokitProviderConfig struct { Default *MicroServiceConfig `mapstructure:"default"` Items []*MicroServiceConfig `mapstructure:"items"` }
type GrpcClientManager ¶
type GrpcClientManager struct { *BaseGokitClient Options []kitgrpc.ClientOption }
func (GrpcClientManager) CreateConnection ¶
func (cm GrpcClientManager) CreateConnection(args ...grpc.DialOption) (*grpc.ClientConn, error)
func (GrpcClientManager) CreateEndpoint ¶
func (cm GrpcClientManager) CreateEndpoint(conn *grpc.ClientConn, ap types.GrpcAspect) endpoint.Endpoint
type InjectFunction ¶
type InjectFunction func(logger types.LogProvider, endpointName string) (clientOptions []interface{}, serverOptions []interface{})
type MicroServiceConfig ¶
type MicroServiceConfig struct { Name string `mapstructure:"name"` // middlewares Trace *TraceConfig `mapstructure:"trace"` // 链路追踪 CircuitBreak *CircuitBreakConfig `mapstructure:"circuitbreak"` // 熔断 RateLimit *RateLimitConfig `mapstructure:"ratelimit"` // 限流 // clients and servers Clients []*ClientConfig `mapstructure:"clients"` Servers []*ServerConfig `mapstructure:"servers"` }
MicroServiceConfig 微服务配置
type MicroServiceImpl ¶
type MicroServiceImpl struct { Name string Logger types.LogProvider Config *MicroServiceConfig }
func (MicroServiceImpl) GetClientConfig ¶
func (msi MicroServiceImpl) GetClientConfig(transport string) *ClientConfig
func (MicroServiceImpl) GetServerConfig ¶
func (msi MicroServiceImpl) GetServerConfig(transport string) *ServerConfig
func (MicroServiceImpl) NewGrpcClientManager ¶
func (msi MicroServiceImpl) NewGrpcClientManager() types.GrpcClientManager
NewGrpcClientManager 创建微服务client manager
func (MicroServiceImpl) NewGrpcServerManager ¶
func (msi MicroServiceImpl) NewGrpcServerManager() types.GrpcServerManager
NewGrpcServerManager 创建微服务server manager
func (MicroServiceImpl) NewHttpServerManager ¶
func (msi MicroServiceImpl) NewHttpServerManager() types.HttpServerManager
NewHttpServerManager 创建微服务server
type MsMiddleware ¶
type MsMiddleware struct { Middleware endpoint.Middleware InjectFunctions map[string]InjectFunction }
MsMiddleware 因为有的中间件是处理的时候需要做一些动作, 有的中间件是需要在ClientOption或者serverOption前做一些动作 我们将不同类型的中间件抽象出来成未MsMiddleware
func NewMdwCircuitBreak ¶
func NewMdwCircuitBreak(config *MicroServiceConfig) *MsMiddleware
NewMdwCircuitBreak 服务熔断
func NewMdwRateLimit ¶
func NewMdwRateLimit(config *MicroServiceConfig) *MsMiddleware
NewMdwRateLimit 服务限流, limited to 1 request per second with burst of 100 requests. Note, rate is defined as a number of requests per second.
func NewMdwTrace ¶
func NewMdwTrace(config *MicroServiceConfig) *MsMiddleware
NewMdwTrace returns an endpoint.Middleware that acts as a tracer. Requests that would exceed the maximum request rate are simply rejected with an error.
type NewMiddlewareFunc ¶
type NewMiddlewareFunc func(config *MicroServiceConfig) *MsMiddleware
type RateLimitConfig ¶
type RateLimitConfig struct { Limit float64 `mapstructure:"limit"` // 每秒允许多少个事件 Burst int `mapstructure:"burst"` // 突发最多允许多少个 }
RateLimitConfig 服务限流选项
type ServerConfig ¶
type ServerConfig struct { Transport string `mapstructure:"transport"` Address string `mapstructure:"address"` Middlewares []string `mapstructure:"middlewares"` }
ServerConfig 服务端配置
type TraceConfig ¶
type TraceConfig struct { Url string `mapstructure:"url"` // Zipkin tracing HTTP reporter URL Address string `mapstructure:"address"` }
TraceConfig 服务跟踪选项