Documentation ¶
Overview ¶
Package xhttp implements web utility functions.
Usage
xhttp.GET("/", func(ctx xhttp.Context) { ctx.TEXT(xhttp.StatusOK, "index") }) xhttp.Run()
Index ¶
- Constants
- Variables
- func DELETE(path string, handle Handle, permissions ...*xtype.Permission)
- func GET(path string, handle Handle, permissions ...*xtype.Permission)
- func HEAD(path string, handle Handle, permissions ...*xtype.Permission)
- func NewRequest(method, urlStr string, values url.Values) (*http.Request, error)
- func OPTIONS(path string, handle Handle, permissions ...*xtype.Permission)
- func PATCH(path string, handle Handle, permissions ...*xtype.Permission)
- func POST(path string, handle Handle, permissions ...*xtype.Permission)
- func PUT(path string, handle Handle, permissions ...*xtype.Permission)
- func RegisterPreRun(preRun func())
- func Run() error
- func SetLocale(locale string)
- func SetPriority(value int)
- func StatusText(code int) string
- type Context
- type Handle
- type Handler
- type Handlers
- type Router
Constants ¶
const ( // AbortIndex abort index. AbortIndex int8 = math.MaxInt8 / 2 // MIMEJSON application/json. MIMEJSON = "application/json" // MIMEHTML text/html. MIMEHTML = "text/html" // MIMEXML application/xml. MIMEXML = "application/xml" // MIMEXML2 text/xml. MIMEXML2 = "text/xml" // MIMEPlain text/plain. MIMEPlain = "text/plain" // MIMEPOSTForm application/x-www-form-urlencoded. MIMEPOSTForm = "application/x-www-form-urlencoded" // MIMEMultipartPOSTForm multipart/form-data. MIMEMultipartPOSTForm = "multipart/form-data" )
const ( StatusContinue = 100 StatusSwitchingProtocols = 101 StatusOK = 200 StatusCreated = 201 StatusAccepted = 202 StatusNonAuthoritativeInfo = 203 StatusNoContent = 204 StatusResetContent = 205 StatusPartialContent = 206 StatusMultipleChoices = 300 StatusMovedPermanently = 301 StatusFound = 302 StatusSeeOther = 303 StatusNotModified = 304 StatusUseProxy = 305 StatusTemporaryRedirect = 307 StatusBadRequest = 400 StatusPaymentRequired = 402 StatusForbidden = 403 StatusNotFound = 404 StatusMethodNotAllowed = 405 StatusNotAcceptable = 406 StatusProxyAuthRequired = 407 StatusRequestTimeout = 408 StatusConflict = 409 StatusGone = 410 StatusLengthRequired = 411 StatusPreconditionFailed = 412 StatusRequestEntityTooLarge = 413 StatusRequestURITooLong = 414 StatusUnsupportedMediaType = 415 StatusRequestedRangeNotSatisfiable = 416 StatusExpectationFailed = 417 StatusTeapot = 418 StatusInternalServerError = 500 StatusNotImplemented = 501 StatusBadGateway = 502 StatusGatewayTimeout = 504 StatusHTTPVersionNotSupported = 505 )
HTTP status codes, defined in RFC 2616.
Variables ¶
var Conf = conf.Conf
Conf web.Conf.
Functions ¶
func DELETE ¶
func DELETE(path string, handle Handle, permissions ...*xtype.Permission)
DELETE adds a route for a HTTP DELETE request to the specified matching pattern.
func GET ¶
func GET(path string, handle Handle, permissions ...*xtype.Permission)
GET adds a route for a HTTP GET request to the specified matching pattern.
func HEAD ¶
func HEAD(path string, handle Handle, permissions ...*xtype.Permission)
HEAD adds a route for a HTTP HEAD request to the specified matching pattern.
func NewRequest ¶
NewRequest returns a new Request given a method, URL, and optional body.
If the provided body is also an io.Closer, the returned Request.Body is set to body and will be closed by the Client methods Do, Post, and PostForm, and Transport.RoundTrip.
NewRequest returns a Request suitable for use with Client.Do or Transport.RoundTrip. To create a request for use with testing a Server Handler use either ReadRequest or manually update the Request fields. See the Request type's documentation for the difference between inbound and outbound request fields.
func OPTIONS ¶
func OPTIONS(path string, handle Handle, permissions ...*xtype.Permission)
OPTIONS adds a route for a HTTP OPTIONS request to the specified matching pattern.
func PATCH ¶
func PATCH(path string, handle Handle, permissions ...*xtype.Permission)
PATCH adds a route for a HTTP PATCH request to the specified matching pattern.
func POST ¶
func POST(path string, handle Handle, permissions ...*xtype.Permission)
POST adds a route for a HTTP POST request to the specified matching pattern.
func PUT ¶
func PUT(path string, handle Handle, permissions ...*xtype.Permission)
PUT adds a route for a HTTP PUT request to the specified matching pattern.
func RegisterPreRun ¶
func RegisterPreRun(preRun func())
RegisterPreRun the registration function is executed before running.
func StatusText ¶
StatusText returns a text for the HTTP status code. It returns the empty string if the code is unknown.
Types ¶
type Context ¶
type Context interface { Request() *http.Request Session() session.Interface ResponseWriter() http.ResponseWriter Params() url.Values Param(key string) string Bind(out entity.Interface) error Attribute(key string) interface{} Attributes() map[string]interface{} SetAttribute(key string, value interface{}) Next() IsAborted() bool Abort() AbortWithStatus(code int) HTML(status int, name string, v interface{}) error JSON(status int, v interface{}) error JSONP(status int, callback string, v interface{}) error XML(status int, v interface{}) error Text(status int, format string, values ...interface{}) error Error(status int) error Redirect(location string, status ...int) error }
Context xhttp.Context.
func NewContext ¶
NewContext new xhttp.Context from http.ResponseWriter and http.Request.
type Handle ¶
type Handle func(c Context)
Handle is a function that can be registered to a route to handle HTTP requests. Like http.HandleFunc.
type Router ¶
type Router interface { Use(middlewares ...Handler) Router GET(pattern string, handle Handle, permissions ...*xtype.Permission) POST(pattern string, handle Handle, permissions ...*xtype.Permission) PUT(pattern string, handle Handle, permissions ...*xtype.Permission) DELETE(pattern string, handle Handle, permissions ...*xtype.Permission) PATCH(pattern string, handle Handle, permissions ...*xtype.Permission) HEAD(pattern string, handle Handle, permissions ...*xtype.Permission) OPTIONS(pattern string, handle Handle, permissions ...*xtype.Permission) ServeHTTP(w http.ResponseWriter, req *http.Request) }
Router xhttp.Router.
Source Files ¶
- api_action.go
- api_context.go
- api_handle.go
- api_render.go
- api_router.go
- core_conf.go
- core_const.go
- core_context.go
- core_engine.go
- core_error.go
- core_handler.go
- core_html.go
- core_i18n.go
- core_init.go
- core_log.go
- core_method.go
- core_recovery.go
- core_render.go
- core_router.go
- core_secure.go
- core_sensitive.go
- core_session.go
- core_static.go
- core_status.go
- core_upload.go
- core_xhttp.go
- doc.go