context

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 14 Imported by: 1

README

http请求处理上下文

Documentation

Index

Constants

View Source
const (
	CheckInt int = iota
	CheckString
	CheckArrayInt
	CheckArrayString
)

批量检测参数

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckField

type CheckField struct {
	Name      string
	Desc      string
	CheckType int
	Request   bool   //是否必填
	Min       int64  //最小值或最小长度
	Max       int64  //最大值或最大长度
	Def       any    //默认值
	Reg       string //正则规则校验
}

CheckField 待检测字段及规则

type Context

type Context struct {
	Ctx            context.Context
	ResponseWriter http.ResponseWriter
	Request        *http.Request
	StartTime      time.Time //记录请求开始处理时间

	Path   string
	Method string

	RequestId string

	StructName string //最终调用的struct name
	MethodName string //最终调用的方法

	//Post     url.Values //单纯的form-data请求数据 或者x-www-form-urlencoded请求数据
	GetPost  url.Values        //get参数与 form-data或者x-www-form-urlencoded合集
	BodyData []byte            //body内包含的数据
	JsonData map[string]string //post + application/json 的情况下,解析后的json数据 [仅限简单结构-请看使用文档]

	ClientIp string //客户端IP

	// 处理返回信息
	CustomRet bool //自定义处理返回信息 跳过统一返回处理
	RetError  string
	RetCode   int
	RetData   any
}

Context 处理请求上下文

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request, structName string, finalStructName string, methodName string) *Context

func (*Context) AddRetError

func (c *Context) AddRetError(err error)

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

func (*Context) CheckField

func (c *Context) CheckField(fields []*CheckField) (map[string]any, error)

func (*Context) ParamDataArrayInt

func (c *Context) ParamDataArrayInt(name string, desc string, require bool, min int64, max int64) (bool, []int64, error)

func (*Context) ParamDataArrayString

func (c *Context) ParamDataArrayString(name string, desc string, require bool, min int64, max int64, reg string) (bool, []string, error)

func (*Context) ParamDataInt

func (c *Context) ParamDataInt(name string, desc string, require bool, min int64, max int64, def int64) (bool, int64, error)

ParamDataInt 检查参数并返回数字

func (*Context) ParamDataString

func (c *Context) ParamDataString(name string, desc string, require bool, min int64, max int64, def string) (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