// Context是gin当中最为重要的一部分 // 它用于在中间件当中传递变量,管理流程。例如接受json请求,并返回json // Context is the most important part of gin. It allows us to pass variables between middleware, // manage the flow, validate the JSON of a request and render a JSON response for example. Context struct { // ServeHTTP 第二个参数,请求体 Req *http.Request // ServeHTTP 第一次参数,响应 Writer http.ResponseWriter // 可以设置的值 Keys map[string]interface{} // 错误信息 Errors []ErrorMsg // 请求参数 Params httprouter.Params // = 中间件 + 请求处理函数(最后一个) handlers []HandlerFunc // Engine 实例 engine *Engine // 当前处理到的Handler下标 index int8 }
// RouterGroup用于管理路由,一个RouterGroup和一个前缀以及一组中间件关联 // Used internally to configure router, a RouterGroup is associated with a prefix // and an array of handlers (middlewares) RouterGroup struct { // 中间件 Handlers []HandlerFunc // 路径前缀 prefix string parent *RouterGroup // Engine 实例 engine *Engine }
// Context是gin当中最为重要的一部分 // 它用于在中间件当中传递变量,管理流程。例如接受json请求,并返回json // Context is the most important part of gin. It allows us to pass variables between middleware, // manage the flow, validate the JSON of a request and render a JSON response for example. Context struct { // ServeHTTP 第二个参数,请求体 Req *http.Request // ServeHTTP 第一次参数,响应 Writer http.ResponseWriter // 可以设置的值 Keys map[string]interface{} // 错误信息 Errors []ErrorMsg // 请求参数 Params httprouter.Params // = 中间件 + 请求处理函数(最后一个) handlers []HandlerFunc // Engine 实例 engine *Engine // 当前处理到的Handler下标 index int8 }
// RouterGroup用于管理路由,一个RouterGroup和一个前缀以及一组中间件关联 // Used internally to configure router, a RouterGroup is associated with a prefix // and an array of handlers (middlewares) RouterGroup struct { // 中间件 Handlers []HandlerFunc // 路径前缀 prefix string parent *RouterGroup // Engine 实例 engine *Engine }