service

package
v0.0.0-...-29b1110 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

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 DecodeGRPCArithmeticRequest

func DecodeGRPCArithmeticRequest(ctx context.Context, r interface{}) (interface{}, error)

func DecodeGRPCArithmeticResponse

func DecodeGRPCArithmeticResponse(_ context.Context, r interface{}) (interface{}, error)

func EncodeGRPCArithmeticRequest

func EncodeGRPCArithmeticRequest(_ context.Context, r interface{}) (interface{}, error)

func EncodeGRPCArithmeticResponse

func EncodeGRPCArithmeticResponse(_ context.Context, r interface{}) (interface{}, error)

func JwtKeyFunc

func JwtKeyFunc(token *jwt.Token) (interface{}, error)

jwtKeyFunc 返回密钥

func MakeArithmeticEndpoint

func MakeArithmeticEndpoint(svc Service) endpoint.Endpoint

MakeArithmeticEndpoint make endpoint

func MakeAuthEndpoint

func MakeAuthEndpoint(svc Service) endpoint.Endpoint

func MakeHealthCheckEndpoint

func MakeHealthCheckEndpoint(svc Service) endpoint.Endpoint

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创建限流中间件

func Register

func Register(consulHost, consulPort, svcHost, svcPort string, logger log.Logger) (registar sd.Registrar)

func Sign

func Sign(name, uid string) (string, error)

Sign 生成token

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

func (ae ArithmeticEndpoints) Calculate(ctx context.Context, reqType string, a, b int) (res int, err error)

func (ArithmeticEndpoints) HealthCheck

func (ae ArithmeticEndpoints) HealthCheck() bool

func (ArithmeticEndpoints) Login

func (ae ArithmeticEndpoints) Login(name, pwd string) (string, error)

HealthCheck

type ArithmeticRequest

type ArithmeticRequest struct {
	RequestType string `json:"request_type"`
	A           int    `json:"a"`
	B           int    `json:"b"`
}

ArithmeticRequest define request struct

type ArithmeticResponse

type ArithmeticResponse struct {
	Result int   `json:"result"`
	Error  error `json:"error"`
}

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。

func (ArithmeticService) Login

func (s ArithmeticService) Login(name, pwd string) (string, error)

type AuthRequest

type AuthRequest struct {
	Name string `json:"name"`
	Pwd  string `json:"pwd"`
}

AuthRequest

type AuthResponse

type AuthResponse struct {
	Success bool   `json:"success"`
	Token   string `json:"token"`
	Error   string `json:"error"`
}

AuthResponse

type HealthRequest

type HealthRequest struct{}

HealthRequest 健康检查请求结构

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

type ServiceMiddleware func(Service) Service

ServiceMiddleware define service middleware

func LoggingMiddleware

func LoggingMiddleware(logger log.Logger) ServiceMiddleware

LoggingMiddleware make logging middleware

func Metrics

func Metrics(requestCount metrics.Counter, requestLatency metrics.Histogram) ServiceMiddleware

Metrics 封装监控方法

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL