Documentation ¶
Index ¶
- Constants
- func ContentTypeByExtension(name string) (t string)
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortCode(code int)
- func (c *Context) Attachment(r io.ReadSeeker, name string) (err error)
- func (c *Context) Body() ([]byte, error)
- func (c *Context) BytesToString(b []byte) string
- func (c *Context) DecodeJSON(obj interface{}) error
- func (c *Context) File(file string)
- func (c *Context) Form(key string) string
- func (c *Context) FormInt(key string, defValue int) int
- func (c *Context) Get(key string) (value interface{}, exists bool)
- func (c *Context) HTML(code int, html string) (err error)
- func (c *Context) IsAborted() bool
- func (c *Context) JSON(code int, i interface{}) (err error)
- func (c *Context) JSONBlob(code int, b []byte) (err error)
- func (c *Context) JSONP(code int, callback string, i interface{}) (err error)
- func (c *Context) MustForm(key string) (string, error)
- func (c *Context) MustFormInt(key string) (int, error)
- func (c *Context) Next()
- func (c *Context) NoContent(code int) error
- func (c *Context) Request() *http.Request
- func (c *Context) Response() http.ResponseWriter
- func (c *Context) Send(method, url string, body []byte) ([]byte, int, error)
- func (c *Context) Set(key string, value interface{})
- func (c *Context) String(code int, s string) (err error)
- func (c *Context) StringToBytes(s string) []byte
- func (c *Context) XML(code int, i interface{}) (err error)
- func (c *Context) XMLBlob(code int, b []byte) (err error)
- type Engine
- func (eng *Engine) Group(path string, middles ...HandlerFunc) *Group
- func (eng *Engine) Handle(path string) IRoute
- func (eng *Engine) IsDebugging() bool
- func (eng *Engine) Middlewares() []HandlerFunc
- func (eng *Engine) Run(addr ...string) error
- func (eng *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (eng *Engine) SetMode(mode Mode)
- func (eng *Engine) Up() IGroup
- func (eng *Engine) Use(middleware ...HandlerFunc)
- type Group
- type HandlerFunc
- type Handlers
- type IGroup
- type ILogger
- type IRoute
- type Mode
- type Param
- type Params
- type ResponseWriter
Constants ¶
View Source
const ( MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack" MIMETextHTML = "text/html" MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8 MIMETextPlain = "text/plain" MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8 MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
MIME types
View Source
const ( HeaderAcceptEncoding = "Accept-Encoding" HeaderAllow = "Allow" HeaderAuthorization = "Authorization" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderIfModifiedSince = "If-Modified-Since" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXForwardedFor = "X-Forwarded-For" HeaderXRealIP = "X-Real-IP" HeaderServer = "Server" HeaderOrigin = "Origin" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" // Security HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-Options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderXCSRFToken = "X-CSRF-Token" )
Headers
View Source
const ( CONNECT = "CONNECT" DELETE = "DELETE" GET = "GET" HEAD = "HEAD" OPTIONS = "OPTIONS" PATCH = "PATCH" POST = "POST" PUT = "PUT" TRACE = "TRACE" )
HTTP methods
Variables ¶
This section is empty.
Functions ¶
func ContentTypeByExtension ¶
ContentTypeByExtension ...
Types ¶
type Context ¶
type Context struct { ResponseWriter Params Params // contains filtered or unexported fields }
Context 请求、响应上下文
func (*Context) Attachment ¶
func (c *Context) Attachment(r io.ReadSeeker, name string) (err error)
Attachment 响应附件 r 文件读取接口 name 文件名 return 返回错误
func (*Context) BytesToString ¶
BytesToString 将二进制数组转换成字符串 b 二进制数组 return 返回字符串
func (*Context) DecodeJSON ¶
DecodeJSON 将响应体解析成对象 obj 转换结果 return 返回错误
func (*Context) MustFormInt ¶
MustFormInt 获取int类型的参数
func (*Context) StringToBytes ¶
StringToBytes 将字符串转换成二进制数组 s 将要被转换的字符串 return 返回二进制数组
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine 框架引擎
func (*Engine) Group ¶
func (eng *Engine) Group(path string, middles ...HandlerFunc) *Group
Group 创建路由组 path 路由组路径 middles 中间件 return 路由组对象
func (*Engine) Middlewares ¶
func (eng *Engine) Middlewares() []HandlerFunc
Middlewares 获取中间件 return 中间件handles
func (*Engine) Use ¶
func (eng *Engine) Use(middleware ...HandlerFunc)
Use 加入中间件 middleware 中间件handle
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group 路由数组
func (*Group) Group ¶
func (g *Group) Group(path string, middles ...HandlerFunc) *Group
Group 创建子路由组 path 组路径 middles 组中件间 return 返回路由组
func (*Group) Middlewares ¶
func (g *Group) Middlewares() []HandlerFunc
Middlewares 获取组路由中间件 return 中间件执行体
type IGroup ¶
type IGroup interface { Use(...HandlerFunc) Handle(string) IRoute Group(string, ...HandlerFunc) *Group Middlewares() []HandlerFunc Up() IGroup }
IGroup 路由组接口
type ILogger ¶
type ILogger interface { SetOutput(io.Writer) Print(...interface{}) Printf(string, ...interface{}) Debug(...interface{}) Debugf(string, ...interface{}) Info(...interface{}) Infof(string, ...interface{}) Warn(...interface{}) Warnf(string, ...interface{}) Error(...interface{}) Errorf(string, ...interface{}) Fatal(...interface{}) Fatalf(string, ...interface{}) }
ILogger 日志记录器接口
type IRoute ¶
type IRoute interface { Connect(...HandlerFunc) IRoute Delete(...HandlerFunc) IRoute Get(...HandlerFunc) IRoute Head(...HandlerFunc) IRoute Options(...HandlerFunc) IRoute Patch(...HandlerFunc) IRoute Post(...HandlerFunc) IRoute Put(...HandlerFunc) IRoute Trace(...HandlerFunc) IRoute Any(...HandlerFunc) }
IRoute 路由接口
type Params ¶
type Params []Param
Params 参数数组
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Hijacker http.Flusher http.CloseNotifier //获取当前请求的响应状态码 Status() int // 返回已写入HTTP响应体的字节数 Size() int // 如果响应正文已被写入,则返回True Written() bool }
ResponseWriter 响应写接口
Click to show internal directories.
Click to hide internal directories.