Documentation ¶
Overview ¶
// +build go1.7
Index ¶
- Constants
- func CleanPath(p string) string
- type Builder
- type Context
- func (c *Context) File(key string) (multipart.File, *multipart.FileHeader, error)
- func (c *Context) Get(key string) string
- func (c *Context) GetWithDefault(key, def string) string
- func (c *Context) Post(key string) string
- func (c *Context) PostWithDefault(key, def string) string
- func (c *Context) Redirect(path string)
- func (c *Context) ResponseJson(data interface{})
- func (c *Context) String(data string)
- type Controller
- type Handle
- type IController
- type MiddlewareHandle
- type Output
- type Param
- type Params
- type Pipeline
- type Route
- func (r *Route) Delete(path string) *Route
- func (r *Route) Get(path string) *Route
- func (r *Route) Middleware(h MiddlewareHandle) *Route
- func (r *Route) MiddlewareGroup(hg []MiddlewareHandle) *Route
- func (r *Route) Mount(rr func(b *Builder)) *Route
- func (r *Route) Name(name string) *Route
- func (r *Route) Patch(path string) *Route
- func (r *Route) Post(path string) *Route
- func (r *Route) Prefix(prefix string) *Route
- func (r *Route) Put(path string) *Route
- func (r *Route) Request(method string, path string, target TargetHandle) *Route
- func (r *Route) Resource(path string, controller IController) *Route
- func (r *Route) Target(target TargetHandle) *Route
- type Router
- func (r *Router) DELETE(path string, route *Route)
- func (r *Router) GET(path string, route *Route)
- func (r *Router) HEAD(path string, route *Route)
- func (r *Router) Handle(method, path string, route *Route)
- func (r *Router) Handler(method, path string, handler http.Handler)
- func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc)
- func (r *Router) Lookup(method, path string) (Route, Params, bool)
- func (r *Router) Mount(routes ...*Route)
- func (r *Router) MountRoute(route *Route)
- func (r *Router) OPTIONS(path string, route *Route)
- func (r *Router) PATCH(path string, route *Route)
- func (r *Router) POST(path string, route *Route)
- func (r *Router) PUT(path string, route *Route)
- func (r *Router) PrintRoutes()
- func (r *Router) ServeFiles(path string, root http.FileSystem)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type TargetHandle
Constants ¶
const DELETE = "DELETE"
const GET = "GET"
const PATCH = "PATCH"
const POST = "POST"
const PUT = "PUT"
Variables ¶
This section is empty.
Functions ¶
func CleanPath ¶
CleanPath is the URL version of path.Clean, it returns a canonical URL path for p, eliminating . and .. elements.
The following rules are applied iteratively until no further processing can be done:
- Replace multiple slashes with a single slash.
- Eliminate each . path name element (the current directory).
- Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
- Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path.
If the result of this process is an empty string, "/" is returned
Types ¶
type Context ¶
type Context struct { Writer http.ResponseWriter // 响应 Request *http.Request // 请求 Params Params //参数 }
上下文结构体
func (*Context) GetWithDefault ¶
func (*Context) PostWithDefault ¶
type Controller ¶
type Controller struct { }
默认基本控制器
func (*Controller) Create ¶
func (cc *Controller) Create(c *Context)
func (*Controller) Destroy ¶
func (cc *Controller) Destroy(c *Context)
func (*Controller) Edit ¶
func (cc *Controller) Edit(c *Context)
func (*Controller) Index ¶
func (cc *Controller) Index(c *Context)
func (*Controller) Show ¶
func (cc *Controller) Show(c *Context)
func (*Controller) Store ¶
func (cc *Controller) Store(c *Context)
func (*Controller) Update ¶
func (cc *Controller) Update(c *Context)
type IController ¶
type IController interface { Index(c *Context) // 对应 get : path方法 Create(c *Context) // 对应 get : path/create 方法 Store(c *Context) // 对应 post : path 方法 Update(c *Context) // 对应put/patch : path/:id 方法 Edit(c *Context) // 对应get : path/:id/edit Show(c *Context) // 对应 get: route/:id Destroy(c *Context) // 对应 delete: route/:id }
控制器接口
type MiddlewareHandle ¶
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
func (*Pipeline) Through ¶
func (p *Pipeline) Through(middlewares []MiddlewareHandle) *Pipeline
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
路由
func (*Route) Middleware ¶
func (r *Route) Middleware(h MiddlewareHandle) *Route
func (*Route) MiddlewareGroup ¶
func (r *Route) MiddlewareGroup(hg []MiddlewareHandle) *Route
func (*Route) Request ¶
func (r *Route) Request(method string, path string, target TargetHandle) *Route
type Router ¶
type Router struct { RedirectTrailingSlash bool RedirectFixedPath bool HandleMethodNotAllowed bool HandleOPTIONS bool NotFound http.HandlerFunc MethodNotAllowed http.Handler PanicHandler func(http.ResponseWriter, *http.Request, interface{}) // contains filtered or unexported fields }
func (*Router) Handle ¶
Handle registers a new request handle with the given path and method.
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).
func (*Router) HandlerFunc ¶
func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc)
HandlerFunc is an adapter which allows the usage of an http.HandlerFunc as a request handle.
func (*Router) Lookup ¶
Lookup allows the manual lookup of a method + path combo. This is e.g. useful to build a framework around this router. If the path was found, it returns the handle function and the path parameter values. Otherwise the third return value indicates whether a redirection to the same path with an extra / without the trailing slash should be performed.
func (*Router) ServeFiles ¶
func (r *Router) ServeFiles(path string, root http.FileSystem)
ServeFiles serves files from the given file system root. The path must end with "/*filepath", files are then served from the local path /defined/root/dir/*filepath. For example if root is "/etc" and *filepath is "passwd", the local file "/etc/passwd" would be served. Internally a http.FileServer is used, therefore http.NotFound is used instead of the Router's NotFound handler. To use the operating system's file system implementation, use http.Dir:
router.ServeFiles("/src/*filepath", http.Dir("/var/www"))
type TargetHandle ¶
type TargetHandle func(c *Context)