Documentation ¶
Index ¶
- Constants
- func GracefulShutdown(srv *http.Server, timeout time.Duration)
- type Application
- func (app *Application) Error(handler ErrorHandlerFunc)
- func (app *Application) NotFound(handler HandlerFunc)
- func (app *Application) RegisterView(view ViewEngine) error
- func (app *Application) Run(addr string) error
- func (app *Application) RunTLS(addr, certFile, keyFile string) error
- func (app *Application) RunWithGracefulShutdown(addr string, timeout time.Duration)
- func (app *Application) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (app *Application) URL(name string, pairs ...interface{}) string
- type Context
- func (c *Context) Abort()
- func (c *Context) Attachment(filepath, filename string) error
- func (c *Context) ClientIP() string
- func (c *Context) ContentType(value string)
- func (c *Context) File(filepath string) error
- func (c *Context) FormFile(name string) (*UploadedFile, error)
- func (c *Context) FormFiles(name string) (*UploadedFiles, error)
- func (c *Context) FormValue(key string) string
- func (c *Context) FormValueDefault(key string, defaultValue string) string
- func (c *Context) FormValueMap(key string) map[string]string
- func (c *Context) FormValueSlice(key string) []string
- func (c *Context) Get(key string) (value interface{}, exists bool)
- func (c *Context) GetCookie(name string) (string, error)
- func (c *Context) Header(name string, value string)
- func (c *Context) IsAborted() bool
- func (c *Context) JSON(obj interface{}) (err error)
- func (c *Context) Layout(layout string)
- func (c *Context) MultipartForm() (*multipart.Form, error)
- func (c *Context) Next() error
- func (c *Context) NoLayout()
- func (c *Context) Param(key string) string
- func (c *Context) PostValue(key string) string
- func (c *Context) PostValueDefault(key string, defaultValue string) string
- func (c *Context) PostValueMap(key string) map[string]string
- func (c *Context) PostValueSlice(key string) []string
- func (c *Context) Query(key string) string
- func (c *Context) QueryDefault(key string, defaultValue string) string
- func (c *Context) QueryMap(key string) map[string]string
- func (c *Context) QuerySlice(key string) []string
- func (c *Context) ReadForm(ptr interface{}) error
- func (c *Context) Redirect(path string, code ...int) error
- func (c *Context) RouteRedirect(name string, pairs ...interface{}) error
- func (c *Context) Set(key string, value interface{})
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) Status(code int)
- func (c *Context) StreamAttachment(r io.Reader, filename string) (err error)
- func (c *Context) Text(format string, data ...interface{}) (err error)
- func (c *Context) URL(name string, pairs ...interface{}) string
- func (c *Context) View(name string, optionalData ...map[string]interface{}) error
- func (c *Context) ViewData(key string, value interface{})
- func (c *Context) WithHeaders(headers map[string]string)
- func (c *Context) Write(b []byte) (int, error)
- func (c *Context) WriteWithStatus(statusCode int, b []byte) (int, error)
- type ErrorHandlerFunc
- type HTMLEngine
- func (v *HTMLEngine) AddFunc(name string, callable interface{})
- func (v *HTMLEngine) Delims(left, right string)
- func (v *HTMLEngine) Func(funcMap template.FuncMap)
- func (v *HTMLEngine) Layout(layout string)
- func (v *HTMLEngine) Load() (err error)
- func (v *HTMLEngine) Render(w io.Writer, name string, layout string, data interface{}, c *Context) error
- type HTTPError
- type HandlerFunc
- type Map
- type Response
- func (res *Response) Flush()
- func (res *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (res *Response) Reset(w http.ResponseWriter) bool
- func (res *Response) Size() int
- func (res *Response) Status() int
- func (res *Response) Write(b []byte) (int, error)
- func (res *Response) WriteHeader(code int)
- func (res *Response) Written() bool
- type Route
- type Router
- func (r *Router) Any(relativePath string, handlers ...HandlerFunc) []*Route
- func (r *Router) DELETE(relativePath string, handlers ...HandlerFunc) *Route
- func (r *Router) File(relativePath, filepath string)
- func (r *Router) GET(relativePath string, handlers ...HandlerFunc) *Route
- func (r *Router) Group(prefix string) *Router
- func (r *Router) HEAD(relativePath string, handlers ...HandlerFunc) *Route
- func (r *Router) Layout(layoutFile string)
- func (r *Router) Match(methods string, relativePath string, handlers ...HandlerFunc) []*Route
- func (r *Router) NoLayout()
- func (r *Router) OPTIONS(relativePath string, handlers ...HandlerFunc) *Route
- func (r *Router) PATCH(relativePath string, handlers ...HandlerFunc) *Route
- func (r *Router) POST(relativePath string, handlers ...HandlerFunc) *Route
- func (r *Router) PUT(relativePath string, handlers ...HandlerFunc) *Route
- func (r *Router) Static(relativePath, root string)
- func (r *Router) Use(middleware ...HandlerFunc)
- type UploadedFile
- type UploadedFiles
- type ViewEngine
Constants ¶
const NoLayout = "no.layout"
NoLayout 不使用视图布局常量
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Application ¶
type Application struct { Router // 内嵌类型 // contains filtered or unexported fields }
Application 负责管理应用程序
func (*Application) Error ¶
func (app *Application) Error(handler ErrorHandlerFunc)
NotFound 添加错误处理程序
func (*Application) NotFound ¶
func (app *Application) NotFound(handler HandlerFunc)
NotFound 添加 NotFound 处理程序
func (*Application) RegisterView ¶
func (app *Application) RegisterView(view ViewEngine) error
RegisterView 注册视图
func (*Application) Run ¶
func (app *Application) Run(addr string) error
Run http.ListenAndServe(addr, app) 的快捷方式
func (*Application) RunTLS ¶
func (app *Application) RunTLS(addr, certFile, keyFile string) error
RunTLS http.ListenAndServeTLS(addr, certFile, keyFile, app) 的快捷方式
func (*Application) RunWithGracefulShutdown ¶
func (app *Application) RunWithGracefulShutdown(addr string, timeout time.Duration)
RunWithGracefulShutdown 带优雅停止的启动
func (*Application) ServeHTTP ¶
func (app *Application) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP 处理 HTTP 请求
func (*Application) URL ¶
func (app *Application) URL(name string, pairs ...interface{}) string
URL 使用命名的路由和参数值创建 URL
type Context ¶
type Context struct { Request *http.Request Response Response // contains filtered or unexported fields }
Context 上下文对象
func (*Context) Attachment ¶
Attachment 文件下载
func (*Context) ContentType ¶
ContentType 设置 Content-Type
func (*Context) FormFile ¶
func (c *Context) FormFile(name string) (*UploadedFile, error)
FormFile 返回给定键的上传文件的 UploadedFile
func (*Context) FormFiles ¶
func (c *Context) FormFiles(name string) (*UploadedFiles, error)
FormFiles 返回给定键的上传文件的 UploadedFiles
func (*Context) FormValueDefault ¶
FormValueDefault 获取表单参数的第一个值,如果参数不存在可以返回指定的默认值
func (*Context) FormValueMap ¶
FormValueMap 获取表单参数映射
func (*Context) FormValueSlice ¶
FormValueSlice 获取表单参数切片
func (*Context) MultipartForm ¶
MultipartForm 取得 multipart/form-data 编码的表单数据
func (*Context) PostValueDefault ¶
PostValueDefault 获取 POST 参数的第一个值,如果参数不存在可以返回指定的默认值
func (*Context) PostValueMap ¶
PostValueMap 获取 POST 参数映射
func (*Context) PostValueSlice ¶
PostValueSlice 获取 POST 参数切片
func (*Context) QueryDefault ¶
QueryDefault 获取查询字符串参数的第一个值,如果参数不存在可以返回指定的默认值
func (*Context) QuerySlice ¶
QuerySlice 获取查询字符串参数切片
func (*Context) RouteRedirect ¶
RouteRedirect 重定向到命名路由
func (*Context) StreamAttachment ¶
StreamAttachment 流下载
func (*Context) WithHeaders ¶
WithHeaders 添加 HTTP 头
type ErrorHandlerFunc ¶
ErrorHandlerFunc 用于错误处理的函数
type HTMLEngine ¶
type HTMLEngine struct {
// contains filtered or unexported fields
}
HTMLEngine HTML 引擎
func (*HTMLEngine) AddFunc ¶
func (v *HTMLEngine) AddFunc(name string, callable interface{})
AddFunc 添加视图函数
type HandlerFunc ¶
HandlerFunc 用于处理请求的函数
type Response ¶
type Response struct { Writer http.ResponseWriter // contains filtered or unexported fields }
Response 包装一个 http.ResponseWriter 并实现其要使用的接口
func (*Response) WriteHeader ¶
WriteHeader 发送 HTTP status code
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router 路由器
func (*Router) Any ¶
func (r *Router) Any(relativePath string, handlers ...HandlerFunc) []*Route
Any 注册实现响应所有 HTTP 请求的路由
func (*Router) DELETE ¶
func (r *Router) DELETE(relativePath string, handlers ...HandlerFunc) *Route
DELETE 注册一个 HTTP DELETE 方法的路由
func (*Router) GET ¶
func (r *Router) GET(relativePath string, handlers ...HandlerFunc) *Route
GET 注册一个 HTTP GET 方法的路由
func (*Router) HEAD ¶
func (r *Router) HEAD(relativePath string, handlers ...HandlerFunc) *Route
HEAD 注册一个 HTTP HEAD 方法的路由
func (*Router) Match ¶
func (r *Router) Match(methods string, relativePath string, handlers ...HandlerFunc) []*Route
Match 注册指定响应 HTTP 请求的路由
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(relativePath string, handlers ...HandlerFunc) *Route
OPTIONS 注册一个 HTTP OPTIONS 方法的路由
func (*Router) PATCH ¶
func (r *Router) PATCH(relativePath string, handlers ...HandlerFunc) *Route
PATCH 注册一个 HTTP PATCH 方法的路由
func (*Router) POST ¶
func (r *Router) POST(relativePath string, handlers ...HandlerFunc) *Route
POST 注册一个 HTTP POST 方法的路由
func (*Router) PUT ¶
func (r *Router) PUT(relativePath string, handlers ...HandlerFunc) *Route
PUT 注册一个 HTTP PUT 方法的路由
type UploadedFile ¶
type UploadedFile struct { File *multipart.FileHeader Name string }
UploadedFile 单个上传的文件
type UploadedFiles ¶
type UploadedFiles struct { Form *multipart.Form Files []*UploadedFile Name string }
UploadedFiles 多个上传的文件