mCtx

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

README

处理请求上下文 处理数据校验 中间件挂载

Documentation

Index

Constants

View Source
const (
	CHECK_INT    checkType = 0
	CHECK_STRING checkType = 1
)

Variables

View Source
var (
	// JSONRETURN 提前退出http请求使用
	JSONRETURN = errors.New("")
	TEXTRETURN = errors.New("")
)

Functions

This section is empty.

Types

type CheckField added in v0.0.10

type CheckField struct {
	Name    string
	Dec     string
	Tpe     checkType
	Request bool   //是否必填
	Def     string //默认值
	Min     int64  //最小值或最小长度
	Max     int64  //最大值或最大长度
	Yewu    bool   //是否为业务参数
	Reg     string //正则规则校验
}

CheckField 用于检查数据的结构信息 checkType 当前仅支持int64 和 string max = 0 表示不限制长度/大小 reg数据校验,多个用|分割 待支持:mobile email ...

type CommonParam

type CommonParam struct {
	AppKey  string `json:"app_key"`
	Control string `json:"control"`
	Method  string `json:"method"`
	Ip      string `json:"ip"`
	Sign    string `json:"sign"`
	Param   string `json:"param"` //业务参数部分
}

CommonParam 公共参数

type Con

type Con struct {
	Request        *http.Request
	ResponseWriter http.ResponseWriter
	RequestId      string //分布式唯一ID

	Header http.Header

	ClassName  string
	MethodName string

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

	CommonParam CommonParam //公共参数 验证签名的请求使用
	YewuParam   YewuParam   //业务参数 验证签名的请求使用
	Node        *snowflake.Node
}

func New

func New(w http.ResponseWriter, r *http.Request, className string, methodName string) (*Con, error)

func (*Con) CheckField added in v0.0.10

func (c *Con) CheckField(fields []*CheckField) (map[string]interface{}, error)

CheckField 批量检查参数是否合法

func (*Con) CheckParamInt

func (c *Con) CheckParamInt(param string, dec string, request bool, min int64, max int64, def string) (int64, error)

CheckParamInt 检测外部访问来的参数 转换为int返回 GET POST参数检测并转换为string dec 字段描述 request 是否必填 min 最小值 max 最大允许值

func (*Con) CheckParamString

func (c *Con) CheckParamString(param string, dec string, request bool, min int64, max int64, def string) (string, error)

CheckParamString 检测外部访问来的参数 GET POST参数检测并转换为string dec 参数描述 request 是否必填 min 0不判断最小长度 max 0 强制max = 65535 判断最大长度 def 默认值

func (*Con) JsonReturn

func (c *Con) JsonReturn(code int, data interface{}, format string, a ...interface{})

func (*Con) WebSocket

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

WebSocket 升级请求为websocket

func (*Con) YewuParamInt

func (c *Con) YewuParamInt(param string, dec string, request bool, min int64, max int64, def string) (int64, error)

YewuParamInt 按字段名 获取业务参数

func (*Con) YewuParamString

func (c *Con) YewuParamString(param string, dec string, request bool, min int64, max int64, def string) (string, error)

YewuParamString 业务参数检测并转换为string

type YewuParam

type YewuParam = map[string]interface{}

YewuParam 业务参数

Jump to

Keyboard shortcuts

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