context

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

README

http请求处理上下文

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CtxPool *sync.Pool

Functions

This section is empty.

Types

type Context

type Context struct {
	StartTime time.Time //记录请求开始处理时间

	Ctx            context.Context
	ResponseWriter http.ResponseWriter

	RetData any //返回数据

	Request *http.Request

	GetPost  url.Values //get参数与 form-data或者x-www-form-urlencoded合集
	BodyData *[]byte    //body内包含的数据

	Valid *valid.Valid //参数校验

	StructFuncName string //最终调用的structFuncName 如果为方法则为自定义名称 如果为struct则为struct/method

	ClientIp string //客户端IP

	RetError  string //错误信息
	RequestId int64  //请求ID
	RetCode   int    //返回码

	CustomRet bool //自定义处理返回信息 跳过统一返回处理
}

Context 处理请求上下文

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request, structFuncName string) *Context

func (*Context) AddRetError

func (c *Context) AddRetError(err error)

AddRetError 向返回错误信息中追加错误内容

func (*Context) CheckField

func (c *Context) CheckField(regs []*valid.Regulation) (map[string]any, error)

func (*Context) ParamDataArrayInt

func (c *Context) ParamDataArrayInt(reg *valid.Regulation) (bool, []int64, error)

func (*Context) ParamDataArrayString

func (c *Context) ParamDataArrayString(reg *valid.Regulation) (bool, []string, error)

func (*Context) ParamDataInt

func (c *Context) ParamDataInt(reg *valid.Regulation) (bool, int64, error)

ParamDataInt 检查参数并返回数字

func (*Context) ParamDataString

func (c *Context) ParamDataString(reg *valid.Regulation) (bool, string, error)

ParamDataString 检查参数并返回字符串值 name 参数名 desc 参数说明 require 是否必须有值 min 最小长度 max 最大长度 0=65535 def 默认值 return exist是否存在参数

func (*Context) WebSocket

func (c *Context) WebSocket() (*websocket.Conn, error)

WebSocket 升级请求为websocket

Jump to

Keyboard shortcuts

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