type(HandlerFuncfunc(*Context)//重命名 这个函数 为 处理函数
Hmap[string]interface{}//重命名 字符-任意类型映射 为 H
// Used internally to collect a error ocurred during a http request.
//在内部用于收集http请求期间发生的错误。(翻译)
ErrorMsgstruct{Messagestring`json:"msg"`Metainterface{}`json:"meta"`}//为一个接收错误信息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.
//上下文是Gin最重要的部分。它允许我们在中间件之间传递变量,
//管理流程,验证请求的JSON并且收到JSON响应。(翻译)
Contextstruct{Req*http.Request//请求指针
Writerhttp.ResponseWriter//响应写入器
Keysmap[string]interface{}//字符-任意类型映射
Errors[]ErrorMsg//错误信息集
Paramshttprouter.Paramshandlers[]HandlerFunc//[]func(*Context) 处理器们
engine*Engine//引擎指针
indexint8//终止符(8位)
}// Used internally to configure router, a RouterGroup is associated with a prefix
// and an array of handlers (middlewares)
//在内部用于配置一个路由,一个路由组与一个前缀相关联
//并且还有一个处理器数组(中间件数组)(翻译)
RouterGroupstruct{Handlers[]HandlerFuncprefixstringparent*RouterGroupengine*Engine}// Represents the web framework, it wrappers the blazing fast httprouter multiplexer and a list of global middlewares.
//代表了Web框架,它包装了快速的httprouter多路复用器和一系列全局中间件。
Enginestruct{*RouterGrouphandlers404[]HandlerFunc//404处理器
router*httprouter.Router//路由
HTMLTemplates*template.Template//html模板
})
// POST is a shortcut for router.Handle("POST", path, handle)
// POST 是一个这个方法的快捷方式
func(group*RouterGroup)POST(pathstring,handlers...HandlerFunc){group.Handle("POST",path,handlers)}// GET is a shortcut for router.Handle("GET", path, handle)
// GET 是一个这个方法的快捷方式
func(group*RouterGroup)GET(pathstring,handlers...HandlerFunc){group.Handle("GET",path,handlers)}// DELETE is a shortcut for router.Handle("DELETE", path, handle)
// DELETE 是一个这个方法的快捷方式
func(group*RouterGroup)DELETE(pathstring,handlers...HandlerFunc){group.Handle("DELETE",path,handlers)}// PATCH is a shortcut for router.Handle("PATCH", path, handle)
// PATCH 是一个这个方法的快捷方式
func(group*RouterGroup)PATCH(pathstring,handlers...HandlerFunc){group.Handle("PATCH",path,handlers)}// PUT is a shortcut for router.Handle("PUT", path, handle)
// PUT 是一个这个方法的快捷方式
func(group*RouterGroup)PUT(pathstring,handlers...HandlerFunc){group.Handle("PUT",path,handlers)}
// Handle registers a new request handle and middlewares with the given path and method.
// The last handler should be the real handler, the other ones should be middlewares that can and should be shared among different routes.
// See the example code in github.
//
// For GET, POST, PUT, PATCH and DELETE requests the respective shortcut
// functions can be used.
//
// This function is intended for bulk loading and to allow the usage of less
// frequently used, non-standardized or custom methods (e.g. for internal
// communication with a proxy).
// Handle 使用给定的path和method注册一个新的request句柄 和 一个处理器
// 最后一个处理程序应该是真正的处理程序,其他处理程序应该是可以而且应该在不同路由之间共享的中间件。
func(group*RouterGroup)Handle(method,pstring,handlers[]HandlerFunc){p=path.Join(group.prefix,p)handlers=group.combineHandlers(handlers)group.engine.router.Handle(method,p,func(whttp.ResponseWriter,req*http.Request,paramshttprouter.Params){group.createContext(w,req,params,handlers).Next()})}
// Writes the given string into the response body and sets the Content-Type to "text/plain"
// 把给的字符串写入 response body 里并且设定内容类型为 "text/plain"
func(c*Context)String(codeint,msgstring){c.Writer.Header().Set("Content-Type","text/plain")c.Writer.WriteHeader(code)c.Writer.Write([]byte(msg))}