Documentation ¶
Overview ¶
Package web 主要用于处理浏览器/服务器之间通信。
Index ¶
- Variables
- type ActionView
- type Application
- func (app *Application) AddMiddleware(name string, ware Middleware, global ...bool)
- func (app *Application) Attr(key string) interface{}
- func (app *Application) AttrString(key string, defaultValue ...string) string
- func (app *Application) Attrs() utils.Attribute
- func (app *Application) Run(addr ...string) (err error)
- func (app *Application) ServeHTTP(writer http.ResponseWriter, request *http.Request)
- func (app *Application) Use(registrations ...interface{})
- type ContentView
- type Context
- type GoTemplateViewEngine
- type HTTPHandler
- type Handler
- type HandlerFunc
- type I18N
- type JsonView
- type Middleware
- type OtplViewEngine
- type Request
- type RequestContext
- func (ctx *RequestContext) APIResult(status int, message string, data ...interface{}) View
- func (ctx *RequestContext) App() *Application
- func (ctx *RequestContext) Attr(name string, value ...interface{}) interface{}
- func (ctx *RequestContext) Content(content string, contentType ...string) View
- func (ctx *RequestContext) Data(name string, value ...interface{}) interface{}
- func (ctx *RequestContext) Empty() View
- func (ctx *RequestContext) JSON(data interface{}, contentType ...string) View
- func (ctx *RequestContext) Param(name string) string
- func (ctx *RequestContext) PathValue(name string) (value string, ok bool)
- func (ctx *RequestContext) Request() *Request
- func (ctx *RequestContext) Response() *Response
- func (ctx *RequestContext) View(template string, contentType ...string) View
- func (ctx *RequestContext) ViewData() map[string]interface{}
- type Response
- type RouteData
- type RouteEntry
- type RouteHttpHandler
- type RouteTable
- type Router
- type RouterGroup
- func (group *RouterGroup) AppendController(controller interface{}) *RouterGroup
- func (group *RouterGroup) Get(pattern string, handler Handler, middlewares ...string) *Router
- func (group *RouterGroup) Group(pattern string, controller interface{}, middlewares ...string) *RouterGroup
- func (group *RouterGroup) Route(method http.HttpMethod, pattern string, handler Handler, middlewares []string) *Router
- type ServiceFunc
- type StaticFileHandler
- type TemplateView
- type View
- type ViewEngine
Constants ¶
This section is empty.
Variables ¶
var DefaultRouterGroup = &RouterGroup{ pattern: "/", routers: make([]*Router, 0), groups: make([]*RouterGroup, 0), }
DefaultRouterGroup 是用于收集默认路由的集合
Functions ¶
This section is empty.
Types ¶
type ActionView ¶
type ActionView struct {
// contains filtered or unexported fields
}
func (*ActionView) ContentType ¶
func (v *ActionView) ContentType() string
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application ...
func (*Application) AddMiddleware ¶
func (app *Application) AddMiddleware(name string, ware Middleware, global ...bool)
AddMiddleware method add a Middleware to Application.
func (*Application) Attr ¶
func (app *Application) Attr(key string) interface{}
func (*Application) AttrString ¶
func (app *Application) AttrString(key string, defaultValue ...string) string
func (*Application) Attrs ¶
func (app *Application) Attrs() utils.Attribute
func (*Application) Run ¶
func (app *Application) Run(addr ...string) (err error)
Run attaches the router to a http.Server and starts listening and serving HTTP requests. It is a shortcut for http.ListenAndServe(addr, router) Note: this method will block the calling goroutine indefinitely unless an error happens.
func (*Application) ServeHTTP ¶
func (app *Application) ServeHTTP(writer http.ResponseWriter, request *http.Request)
ServeHTTP is implements for http.Handler interface
func (*Application) Use ¶
func (app *Application) Use(registrations ...interface{})
Use 设置或注册全局变量、中间件、服务等
type ContentView ¶
type ContentView struct { *ActionView Content string }
func (*ContentView) ContentType ¶
func (v *ContentView) ContentType() string
func (*ContentView) Render ¶
func (ar *ContentView) Render(ctx Context) error
type Context ¶
type Context interface { App() *Application //Response 返回响应写入器 Response() *Response Request() *Request // Attr Gets or sets the HttpApplication object for the current HTTP request. Attr(name string, value ...interface{}) interface{} // Data Gets or sets the Context object for the current HTTP request. Data(name string, value ...interface{}) interface{} ViewData() map[string]interface{} //PathValue returns a route path data with given name PathValue(name string) (value string, ok bool) Param(name string) string Content(content string, contentType ...string) View JSON(data interface{}, contentType ...string) View Empty() View View(template string, contentType ...string) View //APIResult is 推荐的Web API返回结果。 APIResult(status int, message string, data ...interface{}) View }
Context Encapsulates all HTTP-specific information about an individual HTTP request.
type GoTemplateViewEngine ¶
type GoTemplateViewEngine struct {
// contains filtered or unexported fields
}
func GoTemplate ¶
func GoTemplate(ilpath string) *GoTemplateViewEngine
GoTemplate 将使用 GO 原生模板技术作为视图引擎
type HTTPHandler ¶
type HTTPHandler interface { // Init 初始化,并使其为处理请求做好准备。 Init(app *Application) error // Handle 定义处理 HTTP 请求的方法。 Handle(writer http.ResponseWriter, request *http.Request) (complated bool, err error) }
HTTPHandler 定义 HTTP 请求的处理程序。
type HandlerFunc ¶
HandlerFunc 是经过预处理的 Handler 包裹,并作为请求的结果返回或进一步处理。
type JsonView ¶
type JsonView struct { *ActionView Data interface{} }
type Middleware ¶
type Middleware func(Context, HandlerFunc) (int, View)
type OtplViewEngine ¶
type OtplViewEngine struct {
// contains filtered or unexported fields
}
type Request ¶
Request is a http.Request wrapper.
func (*Request) RawRequest ¶
TODO:APIs Form FormValue() FormFile()
type RequestContext ¶
type RequestContext struct {
// contains filtered or unexported fields
}
func (*RequestContext) APIResult ¶
func (ctx *RequestContext) APIResult(status int, message string, data ...interface{}) View
func (*RequestContext) App ¶
func (ctx *RequestContext) App() *Application
func (*RequestContext) Attr ¶
func (ctx *RequestContext) Attr(name string, value ...interface{}) interface{}
func (*RequestContext) Content ¶
func (ctx *RequestContext) Content(content string, contentType ...string) View
func (*RequestContext) Data ¶
func (ctx *RequestContext) Data(name string, value ...interface{}) interface{}
func (*RequestContext) Empty ¶
func (ctx *RequestContext) Empty() View
func (*RequestContext) JSON ¶
func (ctx *RequestContext) JSON(data interface{}, contentType ...string) View
func (*RequestContext) Param ¶
func (ctx *RequestContext) Param(name string) string
func (*RequestContext) PathValue ¶
func (ctx *RequestContext) PathValue(name string) (value string, ok bool)
func (*RequestContext) Request ¶
func (ctx *RequestContext) Request() *Request
func (*RequestContext) Response ¶
func (ctx *RequestContext) Response() *Response
func (*RequestContext) View ¶
func (ctx *RequestContext) View(template string, contentType ...string) View
func (*RequestContext) ViewData ¶
func (ctx *RequestContext) ViewData() map[string]interface{}
type Response ¶
func (*Response) AppendHeader ¶
func (*Response) Writer ¶
func (r *Response) Writer() http.ResponseWriter
type RouteEntry ¶
type RouteEntry struct {
// contains filtered or unexported fields
}
type RouteHttpHandler ¶
type RouteHttpHandler struct {
// contains filtered or unexported fields
}
func URLRouting ¶
func URLRouting(groups ...*RouterGroup) *RouteHttpHandler
func (*RouteHttpHandler) Handle ¶
func (handler *RouteHttpHandler) Handle(writer http.ResponseWriter, request *http.Request) (complated bool, err error)
func (*RouteHttpHandler) Init ¶
func (handler *RouteHttpHandler) Init(app *Application) error
type RouteTable ¶
type RouteTable struct {
// contains filtered or unexported fields
}
func (*RouteTable) Match ¶
func (rt *RouteTable) Match(method http.HttpMethod, url *url.URL) (*RouteData, bool)
Match 匹配
func (*RouteTable) Register ¶
func (rt *RouteTable) Register(method http.HttpMethod, pattern *regexp.Regexp, paramNames []string, handler HandlerFunc, segments int, endsWildcard bool, middlewares []Middleware)
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
func Group ¶
func Group(pattern string, controller interface{}, middlewares ...string) *RouterGroup
func NewGroup ¶
func NewGroup(pattern string, middlewares ...string) *RouterGroup
func (*RouterGroup) AppendController ¶
func (group *RouterGroup) AppendController(controller interface{}) *RouterGroup
func (*RouterGroup) Get ¶
func (group *RouterGroup) Get(pattern string, handler Handler, middlewares ...string) *Router
func (*RouterGroup) Group ¶
func (group *RouterGroup) Group(pattern string, controller interface{}, middlewares ...string) *RouterGroup
func (*RouterGroup) Route ¶
func (group *RouterGroup) Route(method http.HttpMethod, pattern string, handler Handler, middlewares []string) *Router
type StaticFileHandler ¶
type StaticFileHandler struct {
// contains filtered or unexported fields
}
func Static ¶
func Static(root, prefix string, suffix ...string) *StaticFileHandler
func (*StaticFileHandler) Handle ¶
func (handler *StaticFileHandler) Handle(writer http.ResponseWriter, request *http.Request) (complated bool, err error)
func (*StaticFileHandler) Init ¶
func (handler *StaticFileHandler) Init(app *Application) error
type TemplateView ¶
type TemplateView struct { *ActionView Template string }
func (*TemplateView) Render ¶
func (v *TemplateView) Render(ctx Context) error