context

package
v0.0.0-...-be30394 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PoolCloser

func PoolCloser(body []byte) io.ReadCloser

func ReleaseContext

func ReleaseContext(ctx Context)

Types

type Context

type Context interface {
	Init()

	// ShouldBindQuery 反序列化 querystring
	// tag: `form:"xxx"` (注:不要写成 query)
	ShouldBindQuery(obj interface{}) error

	// ShouldBindPostForm 反序列化 postform (querystring会被忽略)
	// tag: `form:"xxx"`
	ShouldBindPostForm(obj interface{}) error

	// ShouldBindForm 同时反序列化 querystring 和 postform;
	// 当 querystring 和 postform 存在相同字段时,postform 优先使用。
	// tag: `form:"xxx"`
	ShouldBindForm(obj interface{}) error

	// ShouldBindJSON 反序列化 postjson
	// tag: `json:"xxx"`
	ShouldBindJSON(obj interface{}) error

	// ShouldBindURI 反序列化 path 参数(如路由路径为 /user/:name)
	// tag: `uri:"xxx"`
	ShouldBindURI(obj interface{}) error

	// Redirect 重定向
	Redirect(code int, location string)

	// Trace 获取 Trace 对象
	Trace() Trace
	SetTrace(trace Trace)
	DisableTrace()

	// Payload 正确返回
	Payload(payload interface{})
	GetPayload() interface{}

	// HTML 返回界面
	HTML(name string, obj interface{})

	// AbortWithError 错误返回
	AbortWithError(err errno.Error)
	AbortError() errno.Error

	// Header 获取 Header 对象
	Header() http.Header
	// GetHeader 获取 Header
	GetHeader(key string) string
	// SetHeader 设置 Header
	SetHeader(key, value string)

	// UserID 获取 UserID
	UserID() int64
	SetUserID(userID int64)

	// UserName 获取 UserName
	UserName() string
	SetUserName(userName string)

	// Alias 设置路由别名 for metrics uri
	Alias() string
	SetAlias(path string)

	// RequestInputParams 获取所有参数
	RequestInputParams() url.Values
	// RequestPostFormParams  获取 PostForm 参数
	RequestPostFormParams() url.Values
	// Request 获取 Request 对象
	Request() *http.Request
	// RawData 获取 Request.Body
	RawData() []byte
	// Method 获取 Request.Method
	Method() string
	// Host 获取 Request.Host
	Host() string
	// Path 获取 请求的路径 Request.URL.Path (不附带 querystring)
	Path() string
	// URI 获取 unescape 后的 Request.URL.RequestURI()
	URI() string
	// RequestContext 获取请求的 context (当 client 关闭后,会自动 canceled)
	RequestContext() StdContext

	// ResponseWriter 获取 ResponseWriter 对象
	ResponseWriter() gin.ResponseWriter

	GetContext() *gin.Context
}

func NewContext

func NewContext(ctx *gin.Context) Context

type HandlerFunc

type HandlerFunc func(c Context)

type OnPanicNotify

type OnPanicNotify func(ctx Context, err interface{}, stackInfo string)

type StdContext

type StdContext struct {
	stdctx.Context
	Trace
}

type Trace

type Trace = trace.T

Jump to

Keyboard shortcuts

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