go第三方库文档 web框架Gin

Constants
Variables
func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine)
func Dir(root string, listDirectory bool) http.FileSystem
func DisableBindValidation()
func DisableConsoleColor()
func EnableJsonDecoderDisallowUnknownFields()
func EnableJsonDecoderUseNumber()
func ForceConsoleColor()
func IsDebugging() bool
func Mode() string
func SetMode(value string)
type Accounts
type Context
    func (c *Context) Abort()
    func (c *Context) AbortWithError(code int, err error) *Error
    func (c *Context) AbortWithStatus(code int)
    func (c *Context) AbortWithStatusJSON(code int, jsonObj interface{})
    func (c *Context) AddParam(key, value string)
    func (c *Context) AsciiJSON(code int, obj interface{})
    func (c *Context) Bind(obj interface{}) error
    func (c *Context) BindHeader(obj interface{}) error
    func (c *Context) BindJSON(obj interface{}) error
    func (c *Context) BindQuery(obj interface{}) error
    func (c *Context) BindUri(obj interface{}) error
    func (c *Context) BindWith(obj interface{}, b binding.Binding) error
    func (c *Context) BindXML(obj interface{}) error
    func (c *Context) BindYAML(obj interface{}) error
    func (c *Context) ClientIP() string
    func (c *Context) ContentType() string
    func (c *Context) Cookie(name string) (string, error)
    func (c *Context) Copy() *Context
    func (c *Context) Data(code int, contentType string, data []byte)
    func (c *Context) DataFromReader(code int, contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string)
    func (c *Context) Deadline() (deadline time.Time, ok bool)
    func (c *Context) DefaultPostForm(key, defaultValue string) string
    func (c *Context) DefaultQuery(key, defaultValue string) string
    func (c *Context) Done() <-chan struct{}
    func (c *Context) Err() error
    func (c *Context) Error(err error) *Error
    func (c *Context) File(filepath string)
    func (c *Context) FileAttachment(filepath, filename string)
    func (c *Context) FileFromFS(filepath string, fs http.FileSystem)
    func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
    func (c *Context) FullPath() string
    func (c *Context) Get(key string) (value interface{}, exists bool)
    func (c *Context) GetBool(key string) (b bool)
    func (c *Context) GetDuration(key string) (d time.Duration)
    func (c *Context) GetFloat64(key string) (f64 float64)
    func (c *Context) GetHeader(key string) string
    func (c *Context) GetInt(key string) (i int)
    func (c *Context) GetInt64(key string) (i64 int64)
    func (c *Context) GetPostForm(key string) (string, bool)
    func (c *Context) GetPostFormArray(key string) (values []string, ok bool)
    func (c *Context) GetPostFormMap(key string) (map[string]string, bool)
    func (c *Context) GetQuery(key string) (string, bool)
    func (c *Context) GetQueryArray(key string) (values []string, ok bool)
    func (c *Context) GetQueryMap(key string) (map[string]string, bool)
    func (c *Context) GetRawData() ([]byte, error)
    func (c *Context) GetString(key string) (s string)
    func (c *Context) GetStringMap(key string) (sm map[string]interface{})
    func (c *Context) GetStringMapString(key string) (sms map[string]string)
    func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)
    func (c *Context) GetStringSlice(key string) (ss []string)
    func (c *Context) GetTime(key string) (t time.Time)
    func (c *Context) GetUint(key string) (ui uint)
    func (c *Context) GetUint64(key string) (ui64 uint64)
    func (c *Context) HTML(code int, name string, obj interface{})
    func (c *Context) Handler() HandlerFunc
    func (c *Context) HandlerName() string
    func (c *Context) HandlerNames() []string
    func (c *Context) Header(key, value string)
    func (c *Context) IndentedJSON(code int, obj interface{})
    func (c *Context) IsAborted() bool
    func (c *Context) IsWebsocket() bool
    func (c *Context) JSON(code int, obj interface{})
    func (c *Context) JSONP(code int, obj interface{})
    func (c *Context) MultipartForm() (*multipart.Form, error)
    func (c *Context) MustBindWith(obj interface{}, b binding.Binding) error
    func (c *Context) MustGet(key string) interface{}
    func (c *Context) Negotiate(code int, config Negotiate)
    func (c *Context) NegotiateFormat(offered ...string) string
    func (c *Context) Next()
    func (c *Context) Param(key string) string
    func (c *Context) PostForm(key string) (value string)
    func (c *Context) PostFormArray(key string) (values []string)
    func (c *Context) PostFormMap(key string) (dicts map[string]string)
    func (c *Context) ProtoBuf(code int, obj interface{})
    func (c *Context) PureJSON(code int, obj interface{})
    func (c *Context) Query(key string) (value string)
    func (c *Context) QueryArray(key string) (values []string)
    func (c *Context) QueryMap(key string) (dicts map[string]string)
    func (c *Context) Redirect(code int, location string)
    func (c *Context) RemoteIP() string
    func (c *Context) Render(code int, r render.Render)
    func (c *Context) SSEvent(name string, message interface{})
    func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
    func (c *Context) SecureJSON(code int, obj interface{})
    func (c *Context) Set(key string, value interface{})
    func (c *Context) SetAccepted(formats ...string)
    func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
    func (c *Context) SetSameSite(samesite http.SameSite)
    func (c *Context) ShouldBind(obj interface{}) error
    func (c *Context) ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (err error)
    func (c *Context) ShouldBindHeader(obj interface{}) error
    func (c *Context) ShouldBindJSON(obj interface{}) error
    func (c *Context) ShouldBindQuery(obj interface{}) error
    func (c *Context) ShouldBindUri(obj interface{}) error
    func (c *Context) ShouldBindWith(obj interface{}, b binding.Binding) error
    func (c *Context) ShouldBindXML(obj interface{}) error
    func (c *Context) ShouldBindYAML(obj interface{}) error
    func (c *Context) Status(code int)
    func (c *Context) Stream(step func(w io.Writer) bool) bool
    func (c *Context) String(code int, format string, values ...interface{})
    func (c *Context) Value(key interface{}) interface{}
    func (c *Context) XML(code int, obj interface{})
    func (c *Context) YAML(code int, obj interface{})
type Engine
    func Default() *Engine
    func New() *Engine
    func (engine *Engine) Delims(left, right string) *Engine
    func (engine *Engine) HandleContext(c *Context)
    func (engine *Engine) LoadHTMLFiles(files ...string)
    func (engine *Engine) LoadHTMLGlob(pattern string)
    func (engine *Engine) NoMethod(handlers ...HandlerFunc)
    func (engine *Engine) NoRoute(handlers ...HandlerFunc)
    func (engine *Engine) Routes() (routes RoutesInfo)
    func (engine *Engine) Run(addr ...string) (err error)
    func (engine *Engine) RunFd(fd int) (err error)
    func (engine *Engine) RunListener(listener net.Listener) (err error)
    func (engine *Engine) RunTLS(addr, certFile, keyFile string) (err error)
    func (engine *Engine) RunUnix(file string) (err error)
    func (engine *Engine) SecureJsonPrefix(prefix string) *Engine
    func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
    func (engine *Engine) SetFuncMap(funcMap template.FuncMap)
    func (engine *Engine) SetHTMLTemplate(templ *template.Template)
    func (engine *Engine) SetTrustedProxies(trustedProxies []string) error
    func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes
type Error
    func (msg Error) Error() string
    func (msg *Error) IsType(flags ErrorType) bool
    func (msg *Error) JSON() interface{}
    func (msg *Error) MarshalJSON() ([]byte, error)
    func (msg *Error) SetMeta(data interface{}) *Error
    func (msg *Error) SetType(flags ErrorType) *Error
    func (msg *Error) Unwrap() error
type ErrorType
type H
    func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error
type HandlerFunc
    func BasicAuth(accounts Accounts) HandlerFunc
    func BasicAuthForRealm(accounts Accounts, realm string) HandlerFunc
    func Bind(val interface{}) HandlerFunc
    func CustomRecovery(handle RecoveryFunc) HandlerFunc
    func CustomRecoveryWithWriter(out io.Writer, handle RecoveryFunc) HandlerFunc
    func ErrorLogger() HandlerFunc
    func ErrorLoggerT(typ ErrorType) HandlerFunc
    func Logger() HandlerFunc
    func LoggerWithConfig(conf LoggerConfig) HandlerFunc
    func LoggerWithFormatter(f LogFormatter) HandlerFunc
    func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc
    func Recovery() HandlerFunc
    func RecoveryWithWriter(out io.Writer, recovery ...RecoveryFunc) HandlerFunc
    func WrapF(f http.HandlerFunc) HandlerFunc
    func WrapH(h http.Handler) HandlerFunc
type HandlersChain
    func (c HandlersChain) Last() HandlerFunc
type IRouter
type IRoutes
type LogFormatter
type LogFormatterParams
    func (p *LogFormatterParams) IsOutputColor() bool
    func (p *LogFormatterParams) MethodColor() string
    func (p *LogFormatterParams) ResetColor() string
    func (p *LogFormatterParams) StatusCodeColor() string
type LoggerConfig
type Negotiate
type Param
type Params
    func (ps Params) ByName(name string) (va string)
    func (ps Params) Get(name string) (string, bool)
type RecoveryFunc
type ResponseWriter
type RouteInfo
type RouterGroup
    func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes
    func (group *RouterGroup) BasePath() string
    func (group *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) IRoutes
    func (group *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) IRoutes
    func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup
    func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRoutes
    func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes
    func (group *RouterGroup) OPTIONS(relativePath string, handlers ...HandlerFunc) IRoutes
    func (group *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc) IRoutes
    func (group *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) IRoutes
    func (group *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) IRoutes
    func (group *RouterGroup) Static(relativePath, root string) IRoutes
    func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRoutes
    func (group *RouterGroup) StaticFile(relativePath, filepath string) IRoutes
    func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes
type RoutesInfo
Package files
auth.go context.go context_appengine.go debug.go deprecated.go doc.go errors.go 
fs.go gin.go logger.go mode.go path.go recovery.go response_writer.go 
routergroup.go test_helpers.go tree.go utils.go version.go

Constants
最常见的数据格式的内容类型MIME。

const (
    MIMEJSON              = binding.MIMEJSON
    MIMEHTML              = binding.MIMEHTML
    MIMEXML               = binding.MIMEXML
    MIMEXML2              = binding.MIMEXML2
    MIMEPlain             = binding.MIMEPlain
    MIMEPOSTForm          = binding.MIMEPOSTForm
    MIMEMultipartPOSTForm = binding.MIMEMultipartPOSTForm
    MIMEYAML              = binding.MIMEYAML
)
可信平台

const (
    // 在谷歌应用程序引擎上运行时。信任X-Appengine-Remote-Addr
    // 在使用Cloudflare的CDN时确定客户端的IP
    PlatformGoogleAppEngine = "X-Appengine-Remote-Addr"
    // 。信任CF连接IP确定
    // 客户端的IP
    PlatformCloudflare = "CF-Connecting-IP"
)
const (
    // 调试模式表示gin模式为调试模式。
    DebugMode = "debug"
    // 释放模式表示gin模式为释放模式。
    ReleaseMode = "release"
    // 测试模式表示gin模式为测试模式。
    TestMode = "test"
)
AuthUserKey是基本身份验证中用户凭据的cookie名称。

const AuthUserKey = "user"
BindKey表示默认的绑定键。

const BindKey = "_gin-gonic/gin/bindkey"
BodyBytesKey表示默认的正文字节键。

const BodyBytesKey = "_gin-gonic/gin/bodybyteskey"
EnvGinMode表示gin模式的环境名称。

const EnvGinMode = "GIN_MODE"
版本是当前gin框架的版本。

const Version = "v1.7.7"
Variables
DebugPrintRouteFunc表示调试日志输出格式。

var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)
默认错误编写器是gin用来调试错误的默认io.Writer

var DefaultErrorWriter io.Writer = os.Stderr
DefaultWriter是Gin用于调试输出的默认io.Writer,以及 Logger()或Recovery()等中间件输出。
 请注意,记录器和恢复都提供自定义方式来配置其 输出io.Writer。 要在Windows中支持着色,
 请使用: 导入“github.com/mattn/go colorable” gin.DefaultWriter=colorable.NewColorableStdout()

var DefaultWriter io.Writer = os.Stdout
func CreateTestContext
func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine)
CreateTestContext返回用于测试目的的新引擎和上下文

func Dir
func Dir(root string, listDirectory bool) http.FileSystem
Dir返回可由http.FileServer()使用的http.FileSystem。在router.Static()中内部使用 
。 如果listDirectory==true,则其工作原理与http.Dir()相同,
否则返回 一个阻止http.FileServer()列出目录文件的文件系统。

func DisableBindValidation
func DisableBindValidation()
DisableBindValidation关闭默认验证器。

func DisableConsoleColor
func DisableConsoleColor()
禁用控制台颜色禁用控制台中的颜色输出。

func EnableJsonDecoderDisallowUnknownFields
func EnableJsonDecoderDisallowUnknownFields()
EnableJsonDecoderDisallowUnknownFields为绑定设置true。
enableDecodedisallowUnknownFields为 在JSON解码器实例上调用DisallowUnknownFields方法。

func EnableJsonDecoderUseNumber
func EnableJsonDecoderUseNumber()
EnableJsonDecoderUseNumber为binding.EnableDecoderUseNumber设置为true。
EnableDecoderUseNumber到 在JSON解码器实例上调用UseNumber方法。

func ForceConsoleColor
func ForceConsoleColor()
forceConsole控制台中的强制颜色输出。

func IsDebugging
func IsDebugging() bool
如果框架在调试模式下运行,IsDebugging返回true。 使用SetMode(gin.ReleaseMode)禁用调试模式。

func Mode
func Mode() string
模式返回当前的gin模式。

func SetMode
func SetMode(value string)
SetMode根据输入字符串设置gin模式。

type Accounts
帐户为授权登录的用户/密码列表定义一个键/值。

type Accounts map[string]string
type Context
type Context struct {
    Request *http.Request
    Writer  ResponseWriter

    Params Params

    // 密钥是专门用于每个请求上下文的密钥/值对。
    Keys map[string]interface{}

    // Errors是附加到使用此上下文的所有处理程序/中间件的错误列表。
    Errors errorMsgs

    // Accepted定义了用于内容协商的手动接受格式列表。
    Accepted []string
    // contains filtered or unexported fields
}
func (*Context) Abort
func (c *Context) Abort()
中止阻止调用挂起的处理程序。请注意,这不会停止当前处理程序。 假设您有一个授权中间件,
用于验证当前请求是否已授权。 如果授权失败(例如:密码不匹配),则调用Abort以确保不调用此请求的剩余处理程序 。

func (*Context) AbortWithError
func (c *Context) AbortWithError(code int, err error) *Error
AbortWithError在内部调用'AbortWithStatus()'和'Error()'。 此方法停止链,
写入状态代码并将指定的错误推送到'c.Errors'。 有关详细信息,请参阅Context.Error()。

func (*Context) AbortWithStatus
func (c *Context) AbortWithStatus(code int)
AbortWithStatus调用'Abort()'`并使用指定的状态代码写入头`。 例如,
对请求进行身份验证的失败尝试可以使用:context.AbortWithStatus(401)。

func (*Context) AbortWithStatusJSON
func (c *Context) AbortWithStatusJSON(code int, jsonObj interface{})
AbortWithStatusJSON在内部调用'Abort()',然后调用'JSON'。 此方法停止链,
写入状态代码并返回JSON正文。 它还将内容类型设置为“application/json”。

func (*Context) AddParam
func (c *Context) AddParam(key, value string)
AddParam将param添加到上下文中, 为e2e测试目的将path param key替换为给定值
 示例路由:“/user/:id” AddParam(“id”,1) 结果:“/user/1”

func (*Context) AsciiJSON
func (c *Context) AsciiJSON(code int, obj interface{})
AsciiJSON使用unicode到ASCII字符串将给定结构作为JSON序列化到响应体中。
 它还将内容类型设置为“application/json”。

func (*Context) Bind
func (c *Context) Bind(obj interface{}) error
Bind检查内容类型以自动选择绑定引擎, 根据“内容类型”标题使用不同的绑定:
 /“应用程序/json”-->json绑定 /“应用程序/xml”-->XML绑定 否则-->返回错误。 
 如果Content Type==“application/JSON”使用JSON或XML作为JSON输入,则将请求正文解析为JSON。
  它将json负载解码到指定为指针的结构中。 如果输入无效,则写入400错误并在响应中设置内容类型标题“text/plain”。

func (*Context) BindHeader
func (c *Context) BindHeader(obj interface{}) error
BindHeader是c.MustBindWith(obj,binding.Header)的快捷方式。

func (*Context) BindJSON
func (c *Context) BindJSON(obj interface{}) error
BindJSON是c.MustBindWith(obj,binding.JSON)的快捷方式。

func (*Context) BindQuery
func (c *Context) BindQuery(obj interface{}) error
BindQuery是c.MustBindWith(obj,binding.Query)的快捷方式。

func (*Context) BindUri
func (c *Context) BindUri(obj interface{}) error
BindUri使用binding.Uri绑定传递的结构指针。 如果出现任何错误,它将使用HTTP 400中止请求。

func (*Context) BindWith
func (c *Context) BindWith(obj interface{}, b binding.Binding) error
BindWith使用指定的绑定引擎绑定传递的结构指针。 请参阅绑定包。

func (*Context) BindXML
func (c *Context) BindXML(obj interface{}) error
BindXML是c.MustBindWith(obj,binding.BindXML)的快捷方式。

func (*Context) BindYAML
func (c *Context) BindYAML(obj interface{}) error
bindyml是c.MustBindWith(obj,binding.YAML)的快捷方式。

func (*Context) ClientIP
func (c *Context) ClientIP() string
ClientIP实现了一个尽力而为的算法来返回真实的客户端IP。 它在引擎盖下调用了c.RemoteIP(),
以检查远程IP是否为可信代理。 如果是,它将尝试解析Engine.RemoteIPHeaders中定义的头文件
(默认为[X-Forwarded-For,X-Real-Ip])。 如果头在语法上无效或远程IP与受信任代理不对应, 将返回远程IP(来自Request.RemoteAddr)。

func (*Context) ContentType
func (c *Context) ContentType() string
ContentType返回请求的Content-Type头。

func (*Context) Cookie
func (c *Context) Cookie(name string) (string, error)
Cookie返回请求中提供的命名Cookie,如果未找到,则返回 ErrNoCookie。
并返回指定的cookie未被替换。 如果多个cookie与给定名称匹配,则只返回一个cookie 。

func (*Context) Copy
func (c *Context) Copy() *Context
Copy返回当前上下文的副本,该副本可以在请求范围之外安全使用。
 当必须将上下文传递给goroutine时,必须使用此选项。

func (*Context) Data
func (c *Context) Data(code int, contentType string, data []byte)
Data将一些数据写入正文流并更新HTTP代码。

func (*Context) DataFromReader
func (c *Context) DataFromReader(code int, contentLength int64,contentType string, reader io.Reader, extraHeaders map[string]string)
DataFromReader将指定的读取器写入主体流并更新HTTP代码。

func (*Context) Deadline
func (c *Context) Deadline() (deadline time.Time, ok bool)
当c.请求没有上下文时,Deadline返回没有截止日期(ok==false)。

func (*Context) DefaultPostForm
func (c *Context) DefaultPostForm(key, defaultValue string) string
DefaultPostForm从POST URL编码表单或多部分表单返回指定的键 如果存在,
否则返回指定的defaultValue字符串。 有关详细信息,请参阅:PostForm()和GetPostForm()。

func (*Context) DefaultQuery
func (c *Context) DefaultQuery(key, defaultValue string) string
DefaultQuery返回键控url查询值(如果存在),否则返回指定的defaultValue字符串。 
有关详细信息,请参见:Query()和GetQuery()。 GET/?name=Manu&lastname= c.DefaultQuery
(“name”,“unknown”)==“Manu” c.DefaultQuery(“id”,“none”)==“none” c.DefaultQuery(“lastname”,“none”)==“

func (*Context) Done
func (c *Context) Done() <-chan struct{}
当c.请求没有上下文时,Done返回nil(chan将永远等待)。

func (*Context) Err
func (c *Context) Err() error
当c.请求没有上下文时,Err返回nil。

func (*Context) Error
func (c *Context) Error(err error) *Error
错误将错误附加到当前上下文。错误被推送到错误列表中。 最好为请求解析过程中发生的每个错误调用Error。
 可以使用中间件收集所有错误并将它们一起推送到数据库, 打印日志,或将其附加到HTTP响应中。 如果err为零,则Error将死机。

func (*Context) File
func (c *Context) File(filepath string)
File将指定的文件高效地写入到主体流中。

func (*Context) FileAttachment
func (c *Context) FileAttachment(filepath, filename string)
FileAttachment以高效的方式将指定的文件写入主体流 在客户端,通常会使用给定的文件名下载该文件

func (*Context) FileFromFS
func (c *Context) FileFromFS(filepath string, fs http.FileSystem)
FileFromFS以有效的方式将http.FileSystem中指定的文件写入到主体流中。

func (*Context) FormFile
func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
FormFile返回所提供表单键的第一个文件。

func (*Context) FullPath
func (c *Context) FullPath() string
FullPath返回匹配的路由完整路径。对于未找到的路由 返回空字符串。
 router.GET(“/user/:id”,func(c*gin.Context){ c.FullPath()==”/user/:id })

func (*Context) Get
func (c *Context) Get(key string) (value interface{}, exists bool)
Get返回给定键的值,即:(value,true)。 如果该值不存在,它将返回(nil,false)

func (*Context) GetBool
func (c *Context) GetBool(key string) (b bool)
GetBool将与键关联的值作为布尔值返回。

func (*Context) GetDuration
func (c *Context) GetDuration(key string) (d time.Duration)
GetDuration返回与键关联的值作为持续时间。

func (*Context) GetFloat64
func (c *Context) GetFloat64(key string) (f64 float64)
GetFloat64将与键关联的值作为float64返回。

func (*Context) GetHeader
func (c *Context) GetHeader(key string) string
GetHeader从请求头返回值。

func (*Context) GetInt
func (c *Context) GetInt(key string) (i int)
GetInt以整数形式返回与键关联的值。

func (*Context) GetInt64
func (c *Context) GetInt64(key string) (i64 int64)
GetInt64以整数形式返回与键关联的值。

func (*Context) GetPostForm
func (c *Context) GetPostForm(key string) (string, bool)
GetPostForm类似于PostForm(键)。当存在`(value,true)`(即使该值是空字符串)时,
它从后URL编码的 表单或多部分表单返回指定的键,否则返回(“,false)。
 例如,在更新用户电子邮件的补丁请求期间:
  电子邮件=mail@example.com --> ("mail@example.com,true):=GetPostForm(“电子邮件”) 
  电子邮件=-->(“”,true):=GetPostForm(“电子邮件”) -->(“”,false):=GetPostForm(“电子邮件”)")

func (*Context) GetPostFormArray
func (c *Context) GetPostFormArray(key string) (values []string, ok bool)
GetPostFormArray返回给定表单键的字符串片段,加上 一个布尔值,无论给定键是否至少存在一个值。

func (*Context) GetPostFormMap
func (c *Context) GetPostFormMap(key string) (map[string]string, bool)
GetPostFormMap返回给定表单键的映射,加上布尔值 给定键是否至少存在一个值。

func (*Context) GetQuery
func (c *Context) GetQuery(key string) (string, bool)
GetQuery类似Query(),它返回键控url查询值 如果它存在`(value,true)`(即使该值是空字符串),
 否则它返回`(“”,false)`。 这是'c.Request.URL.Query().Get(key)` Get/?name=Manu&lastname=
  /(“”,false)==c.GetQuery(“id”) /(“”,true)==c.GetQuery(“lastname”)`'

func (*Context) GetQueryArray
func (c *Context) GetQueryArray(key string) (values []string, ok bool)
GetQueryArray返回给定查询键的字符串片段,加上 一个布尔值,无论给定键是否至少存在一个值。

func (*Context) GetQueryMap
func (c *Context) GetQueryMap(key string) (map[string]string, bool)
GetQueryMap返回给定查询键的映射,加上布尔值 给定键是否至少存在一个值。

func (*Context) GetRawData
func (c *Context) GetRawData() ([]byte, error)
GetRawData返回流数据。

func (*Context) GetString
func (c *Context) GetString(key string) (s string)
GetString以字符串形式返回与键关联的值。

func (*Context) GetStringMap
func (c *Context) GetStringMap(key string) (sm map[string]interface{})
GetStringMap将与键关联的值作为接口映射返回。

func (*Context) GetStringMapString
func (c *Context) GetStringMapString(key string) (sms map[string]string)
GetStringMapString将与键关联的值作为字符串映射返回。

func (*Context) GetStringMapStringSlice
func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)
GetStringMapStringSlice将与键关联的值作为字符串片段的映射返回。

func (*Context) GetStringSlice
func (c *Context) GetStringSlice(key string) (ss []string)
GetStringSlice将与键关联的值作为字符串片段返回。

func (*Context) GetTime
func (c *Context) GetTime(key string) (t time.Time)
GetTime将与键关联的值作为时间返回。

func (*Context) GetUint
func (c *Context) GetUint(key string) (ui uint)
GetUint以无符号整数的形式返回与键关联的值。

func (*Context) GetUint64
func (c *Context) GetUint64(key string) (ui64 uint64)
GetUint64将与键关联的值作为无符号整数返回。

func (*Context) HTML
func (c *Context) HTML(code int, name string, obj interface{})
HTML呈现由其文件名指定的HTTP模板。 它还更新HTTP代码,并将内容类型设置为“text/html”。 参见http:

func (*Context) Handler
func (c *Context) Handler() HandlerFunc
Handler返回主处理程序。

func (*Context) HandlerName
func (c *Context) HandlerName() string
HandlerName返回主处理程序的名称。例如,如果处理程序是“handleGetUsers()”,则 此函数将返回“main.handleGetUsers”。

func (*Context) HandlerNames
func (c *Context) HandlerNames() []string
HandlerNames按降序返回此上下文中所有已注册处理程序的列表, 遵循HandlerName()的语义

func (*Context) Header
func (c *Context) Header(key, value string)
Header是c.Writer.Header()Set(键、值)的智能快捷方式。 它在响应中写入一个头
。 如果值=“”,此方法将删除头`c.Writer.header().Del(key)`

func (*Context) IndentedJSON
func (c *Context) IndentedJSON(code int, obj interface{})
IndentedJSON将给定结构序列化为漂亮的JSON(缩进+结束行)到响应体中。
 它还将内容类型设置为“application/json”。 警告:我们建议仅出于开发目的使用此选项
 ,因为打印漂亮的JSON会消耗更多的CPU和带宽。改为使用Context.JSON()。

func (*Context) IsAborted
func (c *Context) IsAborted() bool
如果当前上下文被中止,则Isborted返回true。

func (*Context) IsWebsocket
func (c *Context) IsWebsocket() bool
如果请求头指示客户端正在启动websocket 握手,则IsWebsocket返回true。

func (*Context) JSON
func (c *Context) JSON(code int, obj interface{})
JSON将给定结构作为JSON序列化到响应体中。 它还将内容类型设置为“application/json”。

func (*Context) JSONP
func (c *Context) JSONP(code int, obj interface{})
JSONP将给定结构作为JSON序列化到响应体中。 它在响应体中添加填充,
以从驻留在不同域(而不是客户端)中的服务器请求数据。 它还将内容类型设置为“application/javascript”。

func (*Context) MultipartForm
func (c *Context) MultipartForm() (*multipart.Form, error)
MultipartForm是经过解析的多部分表单,包括文件上载。

func (*Context) MustBindWith
func (c *Context) MustBindWith(obj interface{}, b binding.Binding) error
MustBindWith使用指定的绑定引擎绑定传递的结构指针。 如果出现任何错误,它将使用HTTP 400中止请求。 请参阅绑定包。

func (*Context) MustGet
func (c *Context) MustGet(key string) interface{}
MustGet将返回给定键的值(如果存在),否则它将崩溃。

func (*Context) Negotiate
func (c *Context) Negotiate(code int, config Negotiate)
根据可接受的接受格式协商调用不同的呈现。

func (*Context) NegotiateFormat
func (c *Context) NegotiateFormat(offered ...string) string
NegotiateFormat返回可接受的接受格式。

func (*Context) Next
func (c *Context) Next()
Next只应在中间件内部使用。 它执行调用处理程序内链中的挂起处理程序。 参见GitHub中的示例。

func (*Context) Param
func (c *Context) Param(key string) string
Param返回URL参数的值。 这是c.Params.ByName(key) router.GET(“/user

/})

func (*Context) PostForm
func (c *Context) PostForm(key string) (value string)
PostForm从POST URL编码表单或多部分表单返回指定的键 如果存在,否则返回空字符串“(“”)”。

func (*Context) PostFormArray
func (c *Context) PostFormArray(key string) (values []string)
PostFormArray返回给定表单键的字符串片段。 片的长度取决于给定键的参数数。

func (*Context) PostFormMap
func (c *Context) PostFormMap(key string) (dicts map[string]string)
PostFormMap返回给定表单键的映射。

func (*Context) ProtoBuf
func (c *Context) ProtoBuf(code int, obj interface{})
ProtoBuf将给定结构作为ProtoBuf序列化到响应体中。

func (*Context) PureJSON
func (c *Context) PureJSON(code int, obj interface{})
PureJSON将给定结构作为JSON序列化到响应体中。 PureJSON与JSON不同,它不会用unicode实体替换特殊的html字符。

func (*Context) Query
func (c *Context) Query(key string) (value string)
查询返回键控url查询值(如果存在), 否则返回空字符串“(“”)”。 
这是`c.Request.URL.Query().Get(key)` Get/path?id=1234&name=Manu
&value= c.Query(“id”)==“1234” c.Query(“name”)==“Manu” c.Query(“value”)==“ c.Query(“wtf”)==”

func (*Context) QueryArray
func (c *Context) QueryArray(key string) (values []string)
QueryArray返回给定查询键的字符串片段。 片的长度取决于给定键的参数数。

func (*Context) QueryMap
func (c *Context) QueryMap(key string) (dicts map[string]string)
QueryMap返回给定查询键的映射。

func (*Context) Redirect
func (c *Context) Redirect(code int, location string)
重定向返回到特定位置的HTTP重定向。

func (*Context) RemoteIP
func (c *Context) RemoteIP() string
RemoteIP从Request.RemoteAddr解析IP,规范化并返回IP(不带端口)。

func (*Context) Render
func (c *Context) Render(code int, r render.Render)
Render写入响应头并调用Render.Render来呈现数据。

func (*Context) SSEvent
func (c *Context) SSEvent(name string, message interface{})
SSEvent将服务器发送的事件写入主体流。

func (*Context) SaveUploadedFile
func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
保存上载文件将表单文件上载到特定dst。

func (*Context) SecureJSON
func (c *Context) SecureJSON(code int, obj interface{})
SecureJSON将给定结构作为安全JSON序列化到响应体中。 如果给定的结构是数组值,
则默认在响应体前面加上“while(1)”。 它还将内容类型设置为“application/json”。

func (*Context) Set
func (c *Context) Set(key string, value interface{})
集合用于专门为此上下文存储新的键/值对。 如果以前没有使用过c.Keys,它也会延迟初始化c.Keys。

func (*Context) SetAccepted
func (c *Context) SetAccepted(formats ...string)
SetAccepted集合接受标头数据。

func (*Context) SetCookie
func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
SetCookie将设置cookie头添加到响应编写器的头中。 提供的cookie必须具有有效名称。无效Cookie可能被 悄悄删除。

func (*Context) SetSameSite
func (c *Context) SetSameSite(samesite http.SameSite)
SetSameSite with cookie

func (*Context) ShouldBind
func (c *Context) ShouldBind(obj interface{}) error
ShouldBind检查内容类型以自动选择绑定引擎, 根据“内容类型”标题使用不同的绑定:
 “应用程序/json”-->json绑定 “应用程序/xml”-->XML binding 否则-->返回一个错误 
 如果Content Type==“application/JSON”使用JSON或XML作为JSON输入,它将请求正文解析为JSON。
  它将json负载解码到指定为指针的结构中。 与c.Bind()类似,但此方法不会将响应状态代码设置为400,如果json无效,则会中止。

func (*Context) ShouldBindBodyWith
func (c *Context) ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (err error)
ShouldBindBodyWith与ShouldBindWith类似,但它将请求 body存储到上下文中,并在再次调用时重用。

注意:此方法在绑定前读取正文。因此,如果只需要调用一次,您应该使用 ShouldBindWith以获得更好的性能。

func (*Context) ShouldBindHeader
func (c *Context) ShouldBindHeader(obj interface{}) error
ShouldBindHeader是c.ShouldBindWith(obj,binding.Header)的快捷方式。

func (*Context) ShouldBindJSON
func (c *Context) ShouldBindJSON(obj interface{}) error
ShouldBindJSON是c.ShouldBindWith(obj,binding.JSON)的快捷方式。

func (*Context) ShouldBindQuery
func (c *Context) ShouldBindQuery(obj interface{}) error
ShouldBindQuery是c.ShouldBindWith(obj,binding.Query)的快捷方式。

func (*Context) ShouldBindUri
func (c *Context) ShouldBindUri(obj interface{}) error
ShouldBindUri使用指定的绑定引擎绑定传递的结构指针。

func (*Context) ShouldBindWith
func (c *Context) ShouldBindWith(obj interface{}, b binding.Binding) error
ShouldBindWith使用指定的绑定引擎绑定传递的结构指针。 请参阅绑定包。

func (*Context) ShouldBindXML
func (c *Context) ShouldBindXML(obj interface{}) error
ShouldBindXML是c.ShouldBindWith(obj,binding.XML)的快捷方式。

func (*Context) ShouldBindYAML
func (c *Context) ShouldBindYAML(obj interface{}) error
ShouldBindYAML是c.ShouldBindWith(obj,binding.YAML)的快捷方式。

func (*Context) Status
func (c *Context) Status(code int)
状态设置HTTP响应代码。

func (*Context) Stream
func (c *Context) Stream(step func(w io.Writer) bool) bool
流发送一个流式响应并返回一个布尔值 表示“在流中间客户端断开了连接”

func (*Context) String
func (c *Context) String(code int, format string, values ...interface{})
String将给定字符串写入响应体。

func (*Context) Value
func (c *Context) Value(key interface{}) interface{}
Value返回与键的此上下文关联的值,如果没有值与键关联,则返回nil 。使用 对值的连续调用返回相同的结果。

func (*Context) XML
func (c *Context) XML(code int, obj interface{})
XML将给定的结构作为XML序列化到响应体中。 它还将内容类型设置为“application/xml”。

func (*Context) YAML
func (c *Context) YAML(code int, obj interface{})
YAML将给定结构作为YAML序列化到响应体中。

type Engine
引擎是框架的实例,它包含muxer、中间件和配置设置。 使用New()或Default()创建引擎实例

type Engine struct {
    RouterGroup

    // 如果当前路由无法匹配,但存在带(不带)尾斜杠的路径的
    // 处理程序,则启用自动重定向。
    // 例如,如果请求了/foo/,但只存在/foo的路由,则
    // 客户端将重定向到/foo,GET请求的http状态代码为301
    // 所有其他请求方法的http状态代码为307。
    RedirectTrailingSlash bool

    // 如果启用,路由器将尝试修复当前请求路径,如果没有为其注册
    // 句柄。
    // 首先是多余的路径元素,如../或
    // 之后,路由器对清理后的路径执行不区分大小写的查找。
    // 如果可以找到此路由的句柄,路由器会将
    // 重定向到正确的路径,GET请求的状态代码为301,
    // 所有其他请求方法的状态代码为307。
    // 例如/FOO和/。。
    // RedirectTrailingSlash独立于此选项。
    RedirectFixedPath bool

    // 如果启用,路由器将检查当前路由是否允许另一种方法,如果当前请求无法路由。
    // 如果是这种情况,则会使用'Method Not Allowed'和HTTP状态码405响应请求。
    // 如果不允许使用其他方法,则将请求委托给未找到的
    // 处理程序。
    HandleMethodNotAllowed bool

    // 如果启用,将从请求头解析客户端IP,该请求头
    // 与存储在“(*gin.Engine).RemoteIPHeaders”中的头匹配。如果未获取任何IP
    // ,则返回到从
    // `(*gin.Context).Request.RemoteAddr`获取的IP。
    ForwardedByClientIP bool

    // 不推荐使用:使用值为'gin.PlatformGoogleAppEngine'的'TrustedPlatform',而不是
    // /#726#755如果启用,它将信任以
    // /'X-AppEngine…'开头的某些头,以便更好地与该PaaS集成。
    AppEngine bool

    // 如果启用,url.RawPath将用于查找参数。
    UseRawPath bool

    // 如果为true,则路径值将不被替换。
    // 如果UseRawPath为false(默认情况下),则unescapepath值为true,
    // 将作为url.Path使用,该路径已被unescape。
    UnescapePathValues bool

    // RemoveExtraSlash即使使用额外的斜杠,也可以从URL解析参数。
    // 请参阅PR#1817和issue#1644
    RemoveExtraSlash bool

    // 当
    // /`(*gin.Engine)ForwardedByClientIP`为'true'和
    // /`(*gin.Context)时用于获取客户端IP的头列表。Request.RemoteAddr`至少与其中一个
    RemoteIPHeaders []string

    // 如果设置为值为gin.Platform*的常量,则信任由
    // 该平台设置的头,例如,确定客户端IP
    TrustedPlatform string

    // 指定给http的'maxMemory'参数的值。请求的ParseMultipartForm
    // 方法调用。
    MaxMultipartMemory int64

    HTMLRender render.HTMLRender
    FuncMap    template.FuncMap
    // contains filtered or unexported fields
}
func Default
func Default() *Engine
/默认值返回已连接记录器和恢复中间件的引擎实例。

func New
func New() *Engine
New返回一个新的blank引擎实例,未连接任何中间件。默认情况下,配置为: -重定向跟踪斜杠:
true -重定向固定路径:false -句柄方法不允许:false -由客户端转发:true -用户路径:false -UnescapePathValues:true

func (*Engine) Delims
func (engine *Engine) Delims(left, right string) *Engine
Delims设置模板左Delims和右Delims,并返回引擎实例。

func (*Engine) HandleContext
func (engine *Engine) HandleContext(c *Context)
HandleContext重新输入已重写的上下文。 这可以通过设置新目标的c.Request.URL.Path来实现。
 免责声明:您可以循环自己来处理此问题,明智地使用。

func (*Engine) LoadHTMLFiles
func (engine *Engine) LoadHTMLFiles(files ...string)
加载HTML文件加载HTML文件的一部分 并将结果与HTML呈现程序关联。

func (*Engine) LoadHTMLGlob
func (engine *Engine) LoadHTMLGlob(pattern string)
LoadHTMLGlob加载由glob模式 标识的HTML文件,并将结果与HTML呈现程序关联。

func (*Engine) NoMethod
func (engine *Engine) NoMethod(handlers ...HandlerFunc)
NoMethod设置Engine.HandleMethodNotAllowed=true时调用的处理程序。

func (*Engine) NoRoute
func (engine *Engine) NoRoute(handlers ...HandlerFunc)
NoRoute为NoRoute添加处理程序。默认情况下,它返回404代码。

func (*Engine) Routes
func (engine *Engine) Routes() (routes RoutesInfo)
Routes返回已注册路由的一部分,包括一些有用的信息,例如: http方法、路径和处理程序名称。

func (*Engine) Run
func (engine *Engine) Run(addr ...string) (err error)
Run将路由器连接到http.Server,并开始侦听和服务http请求。
 这是http.ListenAndServe(addr,router)的快捷方式 注意:除非发生错误,否则此方法将无限期阻止调用goroutine。

func (*Engine) RunFd
func (engine *Engine) RunFd(fd int) (err error)
RunFd将路由器连接到http.Server,并开始通过指定的文件描述符侦听和服务http请求 。
 注意:除非发生错误,否则此方法将无限期地阻止调用goroutine。

func (*Engine) RunListener
func (engine *Engine) RunListener(listener net.Listener) (err error)
RunListener将路由器连接到http.Server,并开始通过指定的
net.Listener pkg.go.dev/github.com/gin gonic/gin#readme-don-t-trust-all-proxies侦听和服务http请求。)

func (*Engine) RunTLS
func (engine *Engine) RunTLS(addr, certFile, keyFile string) (err error)
RunTLS将路由器连接到http.Server并开始侦听和服务HTTPS(安全)请求。 这是
http.listendServeTls(addr、certFile、keyFile、router)的快捷方式 
注意:除非发生错误,否则此方法将无限期阻止调用goroutine。有关详细信息,请参阅

func (*Engine) RunUnix
func (engine *Engine) RunUnix(file string) (err error)
运行unix将路由器连接到http.Server,并开始通过指定的unix套接字(即文件)侦听和服务http请求。
 注意:除非发生错误,否则此方法将无限期地阻止调用goroutine。

func (*Engine) SecureJsonPrefix
func (engine *Engine) SecureJsonPrefix(prefix string) *Engine
SecureJsonPrefix设置Context.SecureJSON中使用的SecureJsonPrefix。

func (*Engine) ServeHTTP
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP符合http.Handler接口。

func (*Engine) SetFuncMap
func (engine *Engine) SetFuncMap(funcMap template.FuncMap)
SetFuncMap设置用于template.FuncMap的FuncMap。

func (*Engine) SetHTMLTemplate
func (engine *Engine) SetHTMLTemplate(templ *template.Template)
SetHTMLTemplate将模板与HTML呈现程序关联。

func (*Engine) SetTrustedProxies
func (engine *Engine) SetTrustedProxies(trustedProxies []string) error
SetTrustedProxies设置网络源列表(IPv4地址、 IPv4 CIDR、IPv6地址或IPv6 CIDR)当 
请求头.ForwardedByClientIP`is`true`.`TrustedProxies` /`(*gin.Engine)时,
从中信任包含备用客户端IP的 默认情况下启用此功能,并且默认情况下它还信任所有代理 如果要禁用此功能,
请使用 引擎.SetTrustedProxies(nil),然后使用Context.ClientIP()将 直接返回远程地址。

func (*Engine) Use
func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes
Use将一个全局中间件连接到路由器。i、 e.通过Use()连接的中间件将 包含在每个请求的处理程序链中。
甚至404405,静态文件。。。 例如,这是日志记录器或错误管理中间件的正确位置。

type Error
错误表示错误的规范。

type Error struct {
    Err  error
    Type ErrorType
    Meta interface{}
}
func (Error) Error
func (msg Error) Error() string
错误实现错误接口。

func (*Error) IsType
func (msg *Error) IsType(flags ErrorType) bool
IsType判断一个错误。

func (*Error) JSON
func (msg *Error) JSON() interface{}
JSON创建格式正确的JSON

func (*Error) MarshalJSON
func (msg *Error) MarshalJSON() ([]byte, error)
MarshalJSON实现JSON.Marshaller接口。

func (*Error) SetMeta
func (msg *Error) SetMeta(data interface{}) *Error
SetMeta设置错误的元数据。

func (*Error) SetType
func (msg *Error) SetType(flags ErrorType) *Error
SetType设置错误的类型。

func (*Error) Unwrap
func (msg *Error) Unwrap() error
Unwrap返回已包装的错误,以允许与errors.Is()、errors.As()和errors.Unwrap()的互操作性。Unwrap()

type ErrorType
ErrorType是gin规范中定义的无符号64位错误代码。

type ErrorType uint64
const (
    // ErrorTypeBind在Context.Bind()失败时使用。
    ErrorTypeBind ErrorType = 1 << 63
    // ErrorTypeRender在Context.Render()失败时使用。
    ErrorTypeRender ErrorType = 1 << 62
    // ErrorTypePrivate表示私有错误。
    ErrorTypePrivate ErrorType = 1 << 0
    // ErrorTypePublic表示公共错误。
    ErrorTypePublic ErrorType = 1 << 1
    // ErrorTypeAny表示任何其他错误。
    ErrorTypeAny ErrorType = 1<<64 - 1
    // ErrorTypeNu表示任何其他错误。
    ErrorTypeNu = 2
)
type H
H是map[string]接口{}

type H map[string]interface{}
func (H) MarshalXML
func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error
MarshalXML允许将类型H与xml.Marshal一起使用。

type HandlerFunc
/HandlerFunc将gin中间件使用的处理程序定义为返回值。

type HandlerFunc func(*Context)
func BasicAuth
func BasicAuth(accounts Accounts) HandlerFunc
BasicAuth返回一个基本的HTTP授权中间件。它以map[string]字符串作为参数,其中 键是用户名,值是密码。

func BasicAuthForRealm
func BasicAuthForRealm(accounts Accounts, realm string) HandlerFunc
BasicAuthorRealm返回一个基本HTTP授权中间件。它将map[string]字符串作为参数,
其中 键是用户名,值是密码,以及域的名称。 如果域为空,则默认使用“需要授权”。 tools.ietf.org/html/rfc2617#section-1.2)

func Bind
func Bind(val interface{}) HandlerFunc
Bind是给定接口对象的帮助函数,返回Gin中间件。

func CustomRecovery
func CustomRecovery(handle RecoveryFunc) HandlerFunc
CustomRecovery返回一个中间件,该中间件可以从任何恐慌中恢复,并调用提供的handle func来处理它。

func CustomRecoveryWithWriter
func CustomRecoveryWithWriter(out io.Writer, handle RecoveryFunc) HandlerFunc
CustomRecoveryWithWriter为给定的编写器返回一个中间件,该编写器可以从任何恐慌中恢复,并调用提供的handle func来处理它。

func ErrorLogger
func ErrorLogger() HandlerFunc
ErrorLogger为任何错误类型返回handlerfunc。

func ErrorLoggerT
func ErrorLoggerT(typ ErrorType) HandlerFunc
ErrorLoggerT返回给定错误类型的handlerfunc。

func Logger
func Logger() HandlerFunc
记录器实例将日志写入gin.DefaultWriter的记录器中间件。 默认情况下,gin.DefaultWriter=os.Stdout。

func LoggerWithConfig
func LoggerWithConfig(conf LoggerConfig) HandlerFunc
LoggerWithConfig实例一个带有config的记录器中间件。

func LoggerWithFormatter
func LoggerWithFormatter(f LogFormatter) HandlerFunc
LoggerWithFormatter实例具有指定日志格式函数的记录器中间件。

func LoggerWithWriter
func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc
LoggerWithWriter实例具有指定写入程序缓冲区的记录器中间件。 示例:os.Stdout,一个以写模式打开的文件,一个套接字。。。

func Recovery
func Recovery() HandlerFunc
Recovery返回一个中间件,该中间件可以从任何恐慌中恢复,如果有恐慌,则写入500。

func RecoveryWithWriter
func RecoveryWithWriter(out io.Writer, recovery ...RecoveryFunc) HandlerFunc
RecoveryWithWriter为给定的编写器返回一个中间件,该编写器可以从任何恐慌中恢复,并在有恐慌时写入500。

func WrapF
func WrapF(f http.HandlerFunc) HandlerFunc
WrapF是包装http.HandlerFunc的助手函数,返回Gin中间件。

func WrapH
func WrapH(h http.Handler) HandlerFunc
WrapH是包装http.Handler的帮助函数,返回Gin中间件。

type HandlersChain
HandlersChain定义了一个HandlerFunc数组。

type HandlersChain []HandlerFunc
func (HandlersChain) Last
func (c HandlersChain) Last() HandlerFunc
Last返回链中的最后一个处理程序。i、 e.最后一个处理程序是主处理程序。

type IRouter
IRouter定义所有路由器句柄接口,包括单路由器和组路由器。

type IRouter interface {
    IRoutes
    Group(string, ...HandlerFunc) *RouterGroup
}
type IRoutes
IRoutes定义所有路由器句柄接口。

type IRoutes interface {
    Use(...HandlerFunc) IRoutes

    Handle(string, string, ...HandlerFunc) IRoutes
    Any(string, ...HandlerFunc) IRoutes
    GET(string, ...HandlerFunc) IRoutes
    POST(string, ...HandlerFunc) IRoutes
    DELETE(string, ...HandlerFunc) IRoutes
    PATCH(string, ...HandlerFunc) IRoutes
    PUT(string, ...HandlerFunc) IRoutes
    OPTIONS(string, ...HandlerFunc) IRoutes
    HEAD(string, ...HandlerFunc) IRoutes

    StaticFile(string, string) IRoutes
    Static(string, string) IRoutes
    StaticFS(string, http.FileSystem) IRoutes
}
type LogFormatter
LogFormatter提供传递给LoggerWithFormatter的格式化程序函数的签名

type LogFormatter func(params LogFormatterParams) string
type LogFormatterParams
LogFormatterParams是任何格式化程序在记录时间到来时都将被传递的结构

type LogFormatterParams struct {
    Request *http.Request

    // TimeStamp显示服务器返回响应后的时间。
    TimeStamp time.Time
    // 状态码是HTTP响应码。
    StatusCode int
    // 延迟是服务器处理某个请求所花费的时间。
    Latency time.Duration
    // ClientIP等于上下文的ClientIP方法。
    ClientIP string
    // 方法是为请求提供的HTTP方法。
    Method string
    // 路径是客户端请求的路径。
    Path string
    // 如果处理请求时发生错误,则设置ErrorMessage。
    ErrorMessage string

    // BodySize是响应正文的大小
    BodySize int
    // 键是在请求上下文中设置的键。
    Keys map[string]interface{}
    // contains filtered or unexported fields
}
func (*LogFormatterParams) IsOutputColor
func (p *LogFormatterParams) IsOutputColor() bool
IsOutputColor指示是否可以将颜色输出到日志。

func (*LogFormatterParams) MethodColor
func (p *LogFormatterParams) MethodColor() string
MethodColor是将http方法正确记录到终端的ANSI颜色。

func (*LogFormatterParams) ResetColor
func (p *LogFormatterParams) ResetColor() string
ResetColor重置所有转义属性。

func (*LogFormatterParams) StatusCodeColor
func (p *LogFormatterParams) StatusCodeColor() string
StatusCodeColor是用于将http状态代码正确记录到终端的ANSI颜色。

type LoggerConfig
LoggerConfig定义记录器中间件的配置。

type LoggerConfig struct {
    // 可选。默认值为gin.defaultLogFormatter
    Formatter LogFormatter

    // 输出是写入日志的写入程序。
    // 可选。默认值为gin.DefaultWriter。
    Output io.Writer

    // SkipPaths是一个url路径数组,未写入日志。
    // 可选。
    SkipPaths []string
}
type Negotiate
协商包含所有协商数据。

type Negotiate struct {
    Offered  []string
    HTMLName string
    HTMLData interface{}
    JSONData interface{}
    XMLData  interface{}
    YAMLData interface{}
    Data     interface{}
}
type Param
Param是一个URL参数,由一个键和一个值组成。

type Param struct {
    Key   string
    Value string
}
type Params
Params是路由器返回的参数片。 切片已排序,第一个URL参数也是第一个切片值。 因此,通过索引读取值是安全的。

type Params []Param
func (Params) ByName
func (ps Params) ByName(name string) (va string)
ByName返回键与给定名称匹配的第一个参数的值。 如果找不到匹配的参数,则返回空字符串。

func (Params) Get
func (ps Params) Get(name string) (string, bool)
Get返回键与给定名称匹配的第一个参数的值和布尔值true。 如果找不到匹配的参数,则返回空字符串,布尔值为false。

type RecoveryFunc
RecoveryFunc定义了可通过CustomRecovery的函数。

type RecoveryFunc func(c *Context, err interface{})
type ResponseWriter
应答器。。。

type ResponseWriter interface {
    http.ResponseWriter
    http.Hijacker
    http.Flusher
    http.CloseNotifier

    // 返回当前请求的HTTP响应状态码。
    Status() int

    // 返回已写入响应http正文的字节数。
    // 请参阅writed()
    Size() int

    // 将字符串写入响应体。
    WriteString(string) (int, error)

    // 如果已写入响应主体,则返回true。
    Written() bool

    // 强制写入http头(状态代码+头)。
    WriteHeaderNow()

    // 获取服务器推送的http.Pusher
    Pusher() http.Pusher
}
type RouteInfo
RouteInfo表示请求路由的规范,其中包含方法和路径及其处理程序。

type RouteInfo struct {
    Method      string
    Path        string
    Handler     string
    HandlerFunc HandlerFunc
}
type RouterGroup
路由组在内部用于配置路由器,路由组与 前缀和处理程序数组(中间件)相关联。

type RouterGroup struct {
    Handlers HandlersChain
    // contains filtered or unexported fields
}
func (*RouterGroup) Any
func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes
任何注册一个与所有HTTP方法匹配的路由。 获取、发布、放置、修补、头、选项、删除、连接、跟踪。

func (*RouterGroup) BasePath
func (group *RouterGroup) BasePath() string
BasePath返回路由器组的基本路径。 例如,如果v:=router.Group(“/rest/n/v1/api”),
则v.BasePath()是“/rest/n/v1/api”。

func (*RouterGroup) DELETE
func (group *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) IRoutes
DELETE是router.Handle的快捷方式(“DELETE”,path,Handle)。

func (*RouterGroup) GET
func (group *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) IRoutes
GET是router.Handle的快捷方式(“GET”,path,Handle)。

func (*RouterGroup) Group
func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup
组创建一个新的路由器组。您应该添加所有具有公共中间件或相同路径前缀的路由。
 例如,所有使用公共中间件进行授权的路由都可以分组。

func (*RouterGroup) HEAD
func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRoutes
HEAD是router.Handle的快捷方式(“HEAD”,path,Handle)。

func (*RouterGroup) Handle
func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes
Handle使用给定的路径和方法注册新的请求句柄和中间件。 最后一个处理程序应该是真正的处理程序,
其他处理程序应该是可以并且应该在不同路由之间共享的中间件。 参见GitHub中的示例代码。

对于GET、POST、PUT、PATCH和DELETE请求,可以使用相应的快捷方式 函数。

此函数用于批量加载,允许使用较少的 常用、非标准或自定义方法(例如用于内部 与代理通信)。

func (*RouterGroup) OPTIONS
func (group *RouterGroup) OPTIONS(relativePath string, handlers ...HandlerFunc) IRoutes
OPTIONS是router.Handle的快捷方式(“OPTIONS”,path,Handle)。

func (*RouterGroup) PATCH
func (group *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc) IRoutes
PATCH是router.Handle的快捷方式(“PATCH”,path,Handle)。

func (*RouterGroup) POST
func (group *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) IRoutes
POST是路由器.Handle(“POST”,路径,句柄)的快捷方式。

func (*RouterGroup) PUT
func (group *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) IRoutes
PUT是router.Handle的快捷方式(“PUT”,path,Handle)。

func (*RouterGroup) Static
func (group *RouterGroup) Static(relativePath, root string) IRoutes
Static服务于给定文件系统根目录中的文件。 内部使用http.FileServer,
因此使用http.NotFound代替路由器的NotFound处理程序的 。 
要使用操作系统的文件系统实现, 使用: router.Static(“/Static”,“/var/www”)

func (*RouterGroup) StaticFS
func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRoutes
StaticFS的工作原理与`Static()`类似,但可以使用自定义的`http.FileSystem`。 Gin默认用户:Gin.Dir()

func (*RouterGroup) StaticFile
func (group *RouterGroup) StaticFile(relativePath, filepath string) IRoutes
StaticFile注册一个路由,以便为本地文件系统的单个文件提供服务。 router.StaticFile(“favicon.ico”,“/resources/favicon.ico”)

func (*RouterGroup) Use
func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes
Use将中间件添加到组中,请参见GitHub中的示例代码。

type RoutesInfo
RouteInfo定义一个RouteInfo切片。

type RoutesInfo []RouteInfo

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值