Documentation
¶
Index ¶
- func CleanPath(p string) string
- type Handle
- type Mux
- func (m *Mux) Ctx() *context
- func (m *Mux) Delete(path string, handle Handle)
- func (m *Mux) Get(path string, handle Handle)
- func (m *Mux) Handle(method, path string, handle Handle)
- func (m *Mux) HandleMethodNotAllowed(flag bool)
- func (m *Mux) Head(path string, handle Handle)
- func (m *Mux) MethodNotAllowedHandler(handle Handle)
- func (m *Mux) NotFoundHandler(handle Handle)
- func (m *Mux) Options(path string, handle Handle)
- func (m *Mux) PanicHandlerFunc(handleFunc func(*Request, interface{}))
- func (m *Mux) Patch(path string, handle Handle)
- func (m *Mux) Put(path string, handle Handle)
- func (m *Mux) RedirectFixedPath(flag bool)
- func (m *Mux) RedirectTrailingSlash(flag bool)
- func (m *Mux) ServeFiles(path string, root http.FileSystem)
- func (m *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (m *Mux) Template(tpl *template.Template)
- type Param
- type Params
- type Request
- func (r *Request) Ctx() *context
- func (r *Request) FormFile(key string) (*UploadFile, error)
- func (r *Request) FormValue(key string) string
- func (r *Request) HeadDel(key string, val string)
- func (r *Request) HeadGet(key string) string
- func (r *Request) HeadSet(key string, val string)
- func (r *Request) HttpRequest() *http.Request
- func (r *Request) Query(key string) string
- func (r *Request) RawQuery() string
- func (r *Request) Response() *Response
- type Response
- func (r *Response) Gzip() *Response
- func (r *Response) Html(tplName string, o interface{}) error
- func (r *Response) Json(o interface{}) error
- func (r *Response) Status(status int) *Response
- func (r *Response) String(o string) error
- func (r *Response) Write(data []byte, contentTypes []string) error
- func (r *Response) Xml(o interface{}) error
- type Router
- type UploadFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Mux ¶ added in v1.0.0
type Mux struct {
// contains filtered or unexported fields
}
func (*Mux) HandleMethodNotAllowed ¶ added in v1.0.0
func (*Mux) MethodNotAllowedHandler ¶ added in v1.0.0
func (*Mux) NotFoundHandler ¶ added in v1.0.0
func (*Mux) PanicHandlerFunc ¶ added in v1.0.0
func (*Mux) RedirectFixedPath ¶ added in v1.0.0
func (*Mux) RedirectTrailingSlash ¶ added in v1.0.0
func (*Mux) ServeFiles ¶ added in v1.0.0
func (m *Mux) 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 Request ¶ added in v1.0.0
type Request struct {
// contains filtered or unexported fields
}
func (*Request) FormFile ¶ added in v1.0.0
func (r *Request) FormFile(key string) (*UploadFile, error)
func (*Request) HttpRequest ¶ added in v1.0.0
type Response ¶ added in v1.0.0
type Response struct {
// contains filtered or unexported fields
}
type Router ¶ added in v1.0.0
type Router struct { // Enables automatic redirection if the current route can't be matched but a // handler for the path with (without) the trailing slash exists. // For example if /foo/ is requested but a route only exists for /foo, the // client is redirected to /foo with http status code 301 for GET requests // and 307 for all other request methods. RedirectTrailingSlash bool // If enabled, the router tries to fix the current request path, if no // handle is registered for it. // First superfluous path elements like ../ or // are removed. // Afterwards the router does a case-insensitive lookup of the cleaned path. // If a handle can be found for this route, the router makes a redirection // to the corrected path with status code 301 for GET requests and 307 for // all other request methods. // For example /FOO and /..//Foo could be redirected to /foo. // RedirectTrailingSlash is independent of this option. RedirectFixedPath bool // If enabled, the router checks if another method is allowed for the // current route, if the current request can not be routed. // If this is the case, the request is answered with 'Method Not Allowed' // and HTTP status code 405. // If no other Method is allowed, the request is delegated to the NotFound // handler. HandleMethodNotAllowed bool // Configurable http.HandlerFunc which is called when no matching route is // found. If it is not set, http.NotFound is used. NotFound Handle // Configurable http.HandlerFunc which is called when a request // cannot be routed and HandleMethodNotAllowed is true. // If it is not set, http.Error with http.StatusMethodNotAllowed is used. MethodNotAllowed Handle // Function to handle panics recovered from http handlers. // It should be used to generate a error page and return the http error code // 500 (Internal Server Error). // The handler can be used to keep your server from crashing because of // unrecovered panics. PanicHandler func(*Request, interface{}) // contains filtered or unexported fields }
Router is a http.Handler which can be used to dispatch requests to different handler functions via configurable routes
func (*Router) Lookup ¶ added in v1.0.0
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.
type UploadFile ¶
type UploadFile struct { Data []byte Name string MIMEHeader textproto.MIMEHeader }