http

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserIDKey        = prefix + "/user-id"
	ReqBodyKey       = prefix + "/req-body"
	ResBodyKey       = prefix + "/res-body"
	LoggerReqBodyKey = prefix + "/logger-req-body"
)

定义上下文中的键

Variables

Functions

func GetBody

func GetBody(c *gin.Context) []byte

GetBody Get request body

func GetToken

func GetToken(c *gin.Context) string

GetToken 获取用户令牌

func GetUserID

func GetUserID(c *gin.Context) string

GetUserID 获取用户ID

func NewRouter

func NewRouter(o *Options, logger *zap.Logger, init InitControllers, tracer opentracing.Tracer) *gin.Engine

func NoMethodHandler

func NoMethodHandler() gin.HandlerFunc

NoMethodHandler 未找到请求方法的处理函数

func NoRouteHandler

func NoRouteHandler() gin.HandlerFunc

NoRouteHandler 未找到请求路由的处理函数

func ParseForm

func ParseForm(c *gin.Context, obj interface{}) error

ParseForm 解析Form请求

func ParseJSON

func ParseJSON(c *gin.Context, obj interface{}) error

ParseJSON 解析请求JSON

func ParseQuery

func ParseQuery(c *gin.Context, obj interface{}) error

ParseQuery 解析Query参数

func ResError

func ResError(c *gin.Context, err error, status ...int)

ResError 响应错误

func ResJSON

func ResJSON(c *gin.Context, status int, v interface{})

ResJSON 响应JSON数据

func ResList

func ResList(c *gin.Context, v interface{})

ResList 响应列表数据

func ResOK

func ResOK(c *gin.Context)

ResOK 响应OK

func ResPage

func ResPage(c *gin.Context, v interface{}, pr *PaginationResult)

ResPage 响应分页数据

func ResSuccess

func ResSuccess(c *gin.Context, v interface{})

ResSuccess 响应成功

func SetUserID

func SetUserID(c *gin.Context, userID string)

SetUserID 设定用户ID

Types

type ErrorItem

type ErrorItem struct {
	Code    int    `json:"code"`    // 错误码
	Message string `json:"message"` // 错误信息
}

ErrorItem 响应错误项

type ErrorResult

type ErrorResult struct {
	Error ErrorItem `json:"error"` // 错误项
}

ErrorResult 响应错误

type IDResult

type IDResult struct {
	ID string `json:"id"`
}

IDResult 响应唯一标识

func NewIDResult

func NewIDResult(id string) *IDResult

NewIDResult 创建响应唯一标识实例

type InitControllers

type InitControllers func(r *gin.Engine)

type ListResult

type ListResult struct {
	List       interface{}       `json:"list"`
	Pagination *PaginationResult `json:"pagination,omitempty"`
}

ListResult 响应列表数据

type Options

type Options struct {
	Host string
	Port int
	Mode string
}

func NewOptions

func NewOptions(v *viper.Viper) (*Options, error)

type OrderDirection

type OrderDirection int

OrderDirection 排序方向

const (
	// OrderByASC 升序排序
	OrderByASC OrderDirection = 1
	// OrderByDESC 降序排序
	OrderByDESC OrderDirection = 2
)

type OrderField

type OrderField struct {
	Key       string         // 字段名(字段名约束为小写蛇形)
	Direction OrderDirection // 排序方向
}

OrderField 排序字段

func NewOrderField

func NewOrderField(key string, d OrderDirection) *OrderField

NewOrderField 创建排序字段

func NewOrderFieldWithKeys

func NewOrderFieldWithKeys(keys []string, directions ...map[int]OrderDirection) []*OrderField

NewOrderFieldWithKeys 创建排序字段(默认升序排序),可指定不同key的排序规则 keys 需要排序的key directions 排序规则,按照key的索引指定,索引默认从0开始

func NewOrderFields

func NewOrderFields(orderFields ...*OrderField) []*OrderField

NewOrderFields 创建排序字段列表

type PaginationParam

type PaginationParam struct {
	Pagination bool `form:"-"`                                     // 是否使用分页查询
	OnlyCount  bool `form:"-"`                                     // 是否仅查询count
	Current    uint `form:"current,default=1"`                     // 当前页
	PageSize   uint `form:"pageSize,default=10" binding:"max=100"` // 页大小
}

PaginationParam 分页查询条件

func (PaginationParam) GetCurrent

func (a PaginationParam) GetCurrent() uint

GetCurrent 获取当前页

func (PaginationParam) GetPageSize

func (a PaginationParam) GetPageSize() uint

GetPageSize 获取页大小

type PaginationResult

type PaginationResult struct {
	Total    int  `json:"total"`
	Current  uint `json:"current"`
	PageSize uint `json:"pageSize"`
}

PaginationResult 分页查询结果

type Server

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

func New

func New(o *Options, logger *zap.Logger, router *gin.Engine) (*Server, error)

func (*Server) Application

func (s *Server) Application(name string)

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop() error

type StatusResult

type StatusResult struct {
	Status StatusText `json:"status"` // 状态(OK)
}

StatusResult 响应状态

type StatusText

type StatusText string

StatusText 定义状态文本

const (
	OKStatus    StatusText = "OK"
	ErrorStatus StatusText = "ERROR"
	FailStatus  StatusText = "FAIL"
)

定义HTTP状态文本常量

func (StatusText) String

func (t StatusText) String() string

Directories

Path Synopsis
middlewares

Jump to

Keyboard shortcuts

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