Documentation ¶
Index ¶
- Variables
- func DecodeGRPCArithmeticRequest(ctx context.Context, r interface{}) (interface{}, error)
- func DecodeGRPCArithmeticResponse(_ context.Context, r interface{}) (interface{}, error)
- func EncodeGRPCArithmeticRequest(_ context.Context, r interface{}) (interface{}, error)
- func EncodeGRPCArithmeticResponse(_ context.Context, r interface{}) (interface{}, error)
- func JwtKeyFunc(token *jwt.Token) (interface{}, error)
- func MakeArithmeticEndpoint(svc Service) endpoint.Endpoint
- func MakeAuthEndpoint(svc Service) endpoint.Endpoint
- func MakeHealthCheckEndpoint(svc Service) endpoint.Endpoint
- func NewTokenBucketLimitterWithBuildIn(bkt *rate.Limiter) endpoint.Middleware
- func NewTokenBucketLimitterWithJuju(bkt *ratelimit.Bucket) endpoint.Middleware
- func Register(consulHost, consulPort, svcHost, svcPort string, logger log.Logger) (registar sd.Registrar)
- func Sign(name, uid string) (string, error)
- type ArithmeticCustomClaims
- type ArithmeticEndpoints
- type ArithmeticRequest
- type ArithmeticResponse
- type ArithmeticService
- type AuthRequest
- type AuthResponse
- type HealthRequest
- type HealthResponse
- type Service
- type ServiceMiddleware
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrInvalidRequestType = errors.New("RequestType has only four type: Add,Subtract,Multiply,Divide")
)
View Source
var ErrLimitExceed = errors.New("Rate limit exceed!")
Functions ¶
func MakeArithmeticEndpoint ¶
MakeArithmeticEndpoint make endpoint
func MakeAuthEndpoint ¶
func MakeHealthCheckEndpoint ¶
MakeHealthCheckEndpoint 创建健康检查Endpoint
func NewTokenBucketLimitterWithBuildIn ¶
func NewTokenBucketLimitterWithBuildIn(bkt *rate.Limiter) endpoint.Middleware
NewTokenBucketLimitterWithBuildIn 使用x/time/rate创建限流中间件
func NewTokenBucketLimitterWithJuju ¶
func NewTokenBucketLimitterWithJuju(bkt *ratelimit.Bucket) endpoint.Middleware
NewTokenBucketLimitterWithJuju 使用juju/ratelimit创建限流中间件
Types ¶
type ArithmeticCustomClaims ¶
type ArithmeticCustomClaims struct { UserId string `json:"userId"` Name string `json:"name"` jwt.StandardClaims }
ArithmeticCustomClaims 自定义声明
type ArithmeticEndpoints ¶
type ArithmeticEndpoints struct { CalculateEndpoint endpoint.Endpoint HealthCheckEndpoint endpoint.Endpoint AuthEndpoint endpoint.Endpoint }
CalculateEndpoint define endpoint
func (ArithmeticEndpoints) HealthCheck ¶
func (ae ArithmeticEndpoints) HealthCheck() bool
type ArithmeticRequest ¶
type ArithmeticRequest struct { RequestType string `json:"request_type"` A int `json:"a"` B int `json:"b"` }
ArithmeticRequest define request struct
type ArithmeticResponse ¶
ArithmeticResponse define response struct
type ArithmeticService ¶
type ArithmeticService struct { }
ArithmeticService implement Service interface
func (ArithmeticService) Calculate ¶
func (s ArithmeticService) Calculate(ctx context.Context, reqType string, a, b int) (res int, err error)
Calculate 实现Service接口
func (ArithmeticService) HealthCheck ¶
func (s ArithmeticService) HealthCheck() bool
HealthCheck implement Service method 用于检查服务的健康状态,这里仅仅返回true。
type AuthRequest ¶
AuthRequest
type AuthResponse ¶
type AuthResponse struct { Success bool `json:"success"` Token string `json:"token"` Error string `json:"error"` }
AuthResponse
type HealthResponse ¶
type HealthResponse struct {
Status bool `json:"status"`
}
HealthResponse 健康检查响应结构
type Service ¶
type Service interface { Calculate(ctx context.Context, reqType string, a, b int) (int, error) // HealthCheck check service health status HealthCheck() bool // HealthCheck Login(name, pwd string) (string, error) }
Service Define a service interface
type ServiceMiddleware ¶
ServiceMiddleware define service middleware
func LoggingMiddleware ¶
func LoggingMiddleware(logger log.Logger) ServiceMiddleware
LoggingMiddleware make logging middleware
Source Files ¶
Click to show internal directories.
Click to hide internal directories.