5.03 Context-Gin Context设计分析
PART1. Gin Context设计
type Context struct {
writermem responseWriter
Request *http.Request
Writer ResponseWriter
Params Params
handlers HandlersChain
index int8
fullPath string
engine *Engine
params *Params
skippedNodes *[]skippedNode
mu sync.RWMutex
Keys map[string]any
Errors errorMsgs
Accepted []string
queryCache url.Values
formCache url.Values
// SameSite allows a server to define a cookie attribute making it impossible for
// the browser to send this cookie along with cross-site requests.
sameSite http.SameSite
}PART2. Gin 处理输入
2.1 从指定的key中读取数据的方法

2.2 从不同部位读取数据的方法

2.3 将输入转化为一个具象的结构体的方法

PART3. Gin 处理输出
3.1 返回具体格式响应的方法

3.2 控制Handler调度的方法

3.3 渲染页面的方法

附录
1. cookie的sameSite属性的作用
Last updated