gin

package
v0.0.0-...-43e5fc7 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RespJson     = 0 //返回json 默认返回json
	RespProtobuf = 1 //返回protobuf二进制
)

Variables

View Source
var (
	ToResponse func(context.Context, interface{}, error) (interface{}, int)
)

Functions

func AddFlag

func AddFlag(fs *flag.FlagSet)

func DefaultServer

func DefaultServer(conf *config.ServerConfig) *gin.Engine

func NewServer

func NewServer() *gin.Engine

func ServerReqMetric

func ServerReqMetric() gin.HandlerFunc

func SetResponse

func SetResponse(fc func(ctx context.Context, resp interface{}, err error) (interface{}, int))

自定义返回

func Shutdown

func Shutdown(engine *gin.Engine, ctx context.Context) error

func Start

func Start(engine *gin.Engine)

Types

type JSON

type JSON struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	TTL     int         `json:"ttl"`
	Data    interface{} `json:"data,omitempty"`
}

func TOJSON

func TOJSON(resp interface{}, err error) (data JSON)

默认TOJSON

type ProtoMessage

type ProtoMessage struct {
	Code                 int32    `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Message              string   `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	Data                 []byte   `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func TOPROTO

func TOPROTO(buf []byte, err error) (data *ProtoMessage)

func (*ProtoMessage) ProtoMessage

func (*ProtoMessage) ProtoMessage()

func (*ProtoMessage) Reset

func (m *ProtoMessage) Reset()

func (*ProtoMessage) String

func (m *ProtoMessage) String() string

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter bbr middleware.

func NewRateLimiter

func NewRateLimiter(conf *bbr.Config) (s *RateLimiter)

NewRateLimiter return a ratelimit middleware.

func (*RateLimiter) Limit

func (b *RateLimiter) Limit() gin.HandlerFunc

Limit return a bm handler func.

Jump to

Keyboard shortcuts

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