Documentation ¶
Index ¶
- Constants
- Variables
- func Config() *ini.File
- func GetAddress(args ...interface{}) string
- func MethodNotAllowedHandler(c *Context) error
- func NotFoundHandler(*Context) error
- func ReadFormData(form map[string][]string, data interface{}) error
- func SetConfig(source interface{}, others ...interface{}) (_ *ini.File, err error)
- func StatusText(code int) string
- type Args
- func (a *Args) Bytes() []byte
- func (a *Args) Exist() bool
- func (a *Args) Float32() (f float32, e error)
- func (a *Args) Float64() (f float64, e error)
- func (a *Args) Int() (int, error)
- func (a *Args) Int64() (int64, error)
- func (a *Args) MustFloat32() (f float32)
- func (a *Args) MustFloat64() (f float64)
- func (a *Args) MustInt() int
- func (a *Args) MustInt64() int64
- func (a *Args) MustUint() uint
- func (a *Args) MustUint8() uint8
- func (a *Args) String() string
- func (a *Args) Time() time.Time
- func (a *Args) ToSnakeCase(str ...string) string
- func (a *Args) ToStr(args ...int) (s string)
- type BindUnmarshaler
- type Binder
- type Context
- func (c *Context) Abort() error
- func (c *Context) AddActionHook(key string, function func(), priorities ...int)
- func (c *Context) AddFilterHook(key string, function func([]byte) []byte, priorities ...int)
- func (c *Context) Args(key ...string) *Args
- func (c *Context) Attachment(file, name string) (err error)
- func (c *Context) Bind(i interface{}) error
- func (c *Context) Blob(contentType string, b []byte, status ...int) (err error)
- func (c *Context) Break(status int, err ...error) error
- func (c *Context) Close() error
- func (c *Context) ContentTypeByExtension(name string) (t string)
- func (c *Context) DoActionHook(key string, globals ...bool)
- func (c *Context) DoFilterHook(key string, function func() []byte, globals ...bool) []byte
- func (c *Context) Error(status int, message ...interface{})
- func (c *Context) Form(key string, defaultValue ...string) string
- func (c *Context) FormArgs(key ...string) *Args
- func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Context) FormParams() (url.Values, error)
- func (c *Context) FormValue(name string) string
- func (c *Context) Get(name string) interface{}
- func (c *Context) GetCookie(name string) (*http.Cookie, error)
- func (c *Context) GetCookies() []*http.Cookie
- func (c *Context) GetStore() map[string]interface{}
- func (c *Context) HandleError(err error)
- func (c *Context) Handler() Handler
- func (c *Context) HasActionHook(key string) bool
- func (c *Context) HasFilterHook(key string, globals ...bool) bool
- func (c *Context) HasQueuesMap(key string) bool
- func (c *Context) Inline(file, name string) (err error)
- func (c *Context) IsTLS() bool
- func (c *Context) IsWebSocket() bool
- func (c *Context) JSON(i interface{}, status ...int) (err error)
- func (c *Context) JSONBlob(b []byte, status ...int) (err error)
- func (c *Context) JSONP(callback string, i interface{}, status ...int) (err error)
- func (c *Context) JSONPBlob(callback string, b []byte, status ...int) (err error)
- func (c *Context) JSONPretty(i interface{}, indent string, status ...int) (err error)
- func (c *Context) Kontext() ktx.Context
- func (c *Context) Makross() *Makross
- func (c *Context) MultipartForm() (*multipart.Form, error)
- func (c *Context) NewCookie() *http.Cookie
- func (c *Context) NewHTTPError(status int, message ...interface{}) *HTTPError
- func (c *Context) NewNode(key interface{}, v interface{}, priority int) *prior.Node
- func (c *Context) NewPriorityQueue() *prior.PriorityQueue
- func (c *Context) Next() error
- func (c *Context) NoContent(status ...int) error
- func (c *Context) Param(name string) *Args
- func (c *Context) Parameter(i int) (value string)
- func (c *Context) PostForm(key string, defaultValue ...string) string
- func (c *Context) Pull(key string) interface{}
- func (c *Context) PullStore() map[string]interface{}
- func (c *Context) Push(key string, value interface{})
- func (c *Context) PushStore(data map[string]interface{})
- func (c *Context) Query(name string, defaultValue ...string) string
- func (c *Context) QueryParam(name string) string
- func (c *Context) QueryParams() url.Values
- func (c *Context) QueryString() string
- func (c *Context) Read(data interface{}) error
- func (c *Context) RealIP() string
- func (c *Context) Redirect(url string, status ...int) error
- func (c *Context) RemoveActionHook(key string, globals ...bool)
- func (c *Context) RemoveActionsHook()
- func (c *Context) RemoveFilterHook(key string, globals ...bool)
- func (c *Context) Render(name string, status ...int) (err error)
- func (c *Context) RequestBody() io.Reader
- func (c *Context) RequestHeader(key string) string
- func (c *Context) RequestURI() string
- func (c *Context) Reset(w http.ResponseWriter, r *http.Request)
- func (c *Context) Scheme() string
- func (c *Context) SendFile(filename string, destinationName string) error
- func (c *Context) ServeContent(content io.ReadSeeker, filename string, modtime time.Time) error
- func (c *Context) ServeFile(file string) (err error)
- func (c *Context) Set(name string, value interface{})
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetDataWriter(writer DataWriter)
- func (c *Context) SetHandler(h Handler)
- func (c *Context) SetKontext(ktx ktx.Context)
- func (c *Context) SetPriorityQueueWith(key interface{}) *sync.Map
- func (c *Context) SetStore(data map[string]interface{})
- func (c *Context) Shutdown(times ...int64) error
- func (c *Context) Stream(contentType string, r io.Reader, status ...int) (err error)
- func (c *Context) String(s string, status ...int) (err error)
- func (c *Context) URL(route string, pairs ...interface{}) string
- func (c *Context) UserAgent() string
- func (c *Context) Write(data interface{}) error
- func (c *Context) XML(i interface{}, status ...int) (err error)
- func (c *Context) XMLBlob(b []byte, status ...int) (err error)
- func (c *Context) XMLPretty(i interface{}, indent string, status ...int) (err error)
- type DataReader
- type DataWriter
- type DefaultBinder
- type Flash
- type FormDataReader
- type HTTPError
- type Handler
- type JSONDataReader
- type Localer
- type Makross
- func (m *Makross) AcquireContext() *Context
- func (m *Makross) AddActionHook(key string, function func(), priorities ...int)
- func (m *Makross) AddFilterHook(key string, function func([]byte) []byte, priorities ...int)
- func (m *Makross) Binder() Binder
- func (m *Makross) Close() error
- func (m *Makross) DoActionHook(key string)
- func (m *Makross) DoFilterHook(key string, function func() []byte) []byte
- func (m *Makross) File(path, file string)
- func (m *Makross) HandleError(c *Context, err interface{})
- func (m *Makross) HasActionHook(key string) bool
- func (m *Makross) HasFilterHook(key string) bool
- func (m *Makross) HasQueuesMap(key string) bool
- func (m *Makross) Listen(args ...interface{})
- func (m *Makross) ListenTLS(certFile, keyFile string, args ...interface{})
- func (m *Makross) NewContext(r *http.Request, w http.ResponseWriter, handlers ...Handler) *Context
- func (m *Makross) NewHTTPError(status int, message ...interface{}) *HTTPError
- func (m *Makross) NewNode(key interface{}, v interface{}, priority int) *prior.Node
- func (m *Makross) NewPriorityQueue() *prior.PriorityQueue
- func (r *Makross) NotFound(handlers ...Handler)
- func (m *Makross) Pull(key string) interface{}
- func (m *Makross) PullStore() map[string]interface{}
- func (m *Makross) Push(key string, value interface{})
- func (m *Makross) PushStore(data map[string]interface{})
- func (m *Makross) ReleaseContext(c *Context)
- func (m *Makross) RemoveActionHook(key string)
- func (m *Makross) RemoveActionsHook()
- func (m *Makross) RemoveFilterHook(key string)
- func (m *Makross) Route(name string) *Route
- func (m *Makross) Routes() []*Route
- func (m *Makross) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (m *Makross) SetBinder(b Binder)
- func (m *Makross) SetPriorityQueueWith(key interface{}) *sync.Map
- func (m *Makross) SetRenderer(r Renderer)
- func (m *Makross) Shutdown(times ...int64) error
- func (m *Makross) Static(prefix, root string)
- func (r *Makross) Use(handlers ...Handler)
- type RawStore
- type Renderer
- type Response
- type Route
- func (r *Route) Connect(handlers ...Handler) *Route
- func (r *Route) Delete(handlers ...Handler) *Route
- func (r *Route) Get(handlers ...Handler) *Route
- func (r *Route) Head(handlers ...Handler) *Route
- func (r *Route) Method() string
- func (r *Route) Name(name string) *Route
- func (r *Route) Options(handlers ...Handler) *Route
- func (r *Route) Patch(handlers ...Handler) *Route
- func (r *Route) Path() string
- func (r *Route) Post(handlers ...Handler) *Route
- func (r *Route) Put(handlers ...Handler) *Route
- func (r *Route) String() string
- func (r *Route) Tag(value interface{}) *Route
- func (r *Route) Tags() []interface{}
- func (r *Route) To(methods string, handlers ...Handler) *Route
- func (r *Route) Trace(handlers ...Handler) *Route
- func (r *Route) URL(pairs ...interface{}) (s string)
- type RouteGroup
- func (rg *RouteGroup) Any(path string, handlers ...Handler) *Route
- func (rg *RouteGroup) Connect(path string, handlers ...Handler) *Route
- func (rg *RouteGroup) Delete(path string, handlers ...Handler) *Route
- func (rg *RouteGroup) Get(path string, handlers ...Handler) *Route
- func (rg *RouteGroup) Group(prefix string, handlers ...Handler) *RouteGroup
- func (rg *RouteGroup) Head(path string, handlers ...Handler) *Route
- func (rg *RouteGroup) Options(path string, handlers ...Handler) *Route
- func (rg *RouteGroup) Patch(path string, handlers ...Handler) *Route
- func (rg *RouteGroup) Post(path string, handlers ...Handler) *Route
- func (rg *RouteGroup) Put(path string, handlers ...Handler) *Route
- func (rg *RouteGroup) SetRenderer(r Renderer)
- func (rg *RouteGroup) To(methods, path string, handlers ...Handler) *Route
- func (rg *RouteGroup) Trace(path string, handlers ...Handler) *Route
- func (rg *RouteGroup) Use(handlers ...Handler)
- type Sessioner
- type XMLDataReader
Constants ¶
const ( CONNECT = "CONNECT" DELETE = "DELETE" GET = "GET" HEAD = "HEAD" OPTIONS = "OPTIONS" PATCH = "PATCH" POST = "POST" PUT = "PUT" TRACE = "TRACE" )
Export HTTP methods
const ( MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8 MIMETextXML = "text/xml" MIMETextXMLCharsetUTF8 = MIMETextXML + "; " + charsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack" MIMETextHTML = "text/html" MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8 MIMETextPlain = "text/plain" MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8 MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
MIME types
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" HeaderAllow = "Allow" HeaderAuthorization = "Authorization" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderIfModifiedSince = "If-Modified-Since" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedProtocol = "X-Forwarded-Protocol" HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXUrlScheme = "X-Url-Scheme" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXRealIP = "X-Real-IP" HeaderXRequestID = "X-Request-ID" HeaderServer = "Server" HeaderOrigin = "Origin" // Access control HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" // Security HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-Options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderXCSRFToken = "X-CSRF-Token" )
Headers
const ( StatusContinue = 100 // RFC 7231, 6.2.1 StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2 StatusProcessing = 102 // RFC 2518, 10.1 StatusOK = 200 // RFC 7231, 6.3.1 StatusCreated = 201 // RFC 7231, 6.3.2 StatusAccepted = 202 // RFC 7231, 6.3.3 StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4 StatusNoContent = 204 // RFC 7231, 6.3.5 StatusResetContent = 205 // RFC 7231, 6.3.6 StatusPartialContent = 206 // RFC 7233, 4.1 StatusMultiStatus = 207 // RFC 4918, 11.1 StatusAlreadyReported = 208 // RFC 5842, 7.1 StatusIMUsed = 226 // RFC 3229, 10.4.1 StatusMultipleChoices = 300 // RFC 7231, 6.4.1 StatusMovedPermanently = 301 // RFC 7231, 6.4.2 StatusFound = 302 // RFC 7231, 6.4.3 StatusSeeOther = 303 // RFC 7231, 6.4.4 StatusNotModified = 304 // RFC 7232, 4.1 StatusUseProxy = 305 // RFC 7231, 6.4.5 StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7 StatusPermanentRedirect = 308 // RFC 7538, 3 StatusBadRequest = 400 // RFC 7231, 6.5.1 StatusPaymentRequired = 402 // RFC 7231, 6.5.2 StatusForbidden = 403 // RFC 7231, 6.5.3 StatusNotFound = 404 // RFC 7231, 6.5.4 StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5 StatusNotAcceptable = 406 // RFC 7231, 6.5.6 StatusProxyAuthRequired = 407 // RFC 7235, 3.2 StatusRequestTimeout = 408 // RFC 7231, 6.5.7 StatusConflict = 409 // RFC 7231, 6.5.8 StatusGone = 410 // RFC 7231, 6.5.9 StatusLengthRequired = 411 // RFC 7231, 6.5.10 StatusPreconditionFailed = 412 // RFC 7232, 4.2 StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11 StatusRequestURITooLong = 414 // RFC 7231, 6.5.12 StatusUnsupportedMediaType = 415 // RFC 7231, 6.5.13 StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4 StatusExpectationFailed = 417 // RFC 7231, 6.5.14 StatusTeapot = 418 // RFC 7168, 2.3.3 StatusUnprocessableEntity = 422 // RFC 4918, 11.2 StatusLocked = 423 // RFC 4918, 11.3 StatusFailedDependency = 424 // RFC 4918, 11.4 StatusUpgradeRequired = 426 // RFC 7231, 6.5.15 StatusPreconditionRequired = 428 // RFC 6585, 3 StatusTooManyRequests = 429 // RFC 6585, 4 StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5 StatusInternalServerError = 500 // RFC 7231, 6.6.1 StatusNotImplemented = 501 // RFC 7231, 6.6.2 StatusBadGateway = 502 // RFC 7231, 6.6.3 StatusGatewayTimeout = 504 // RFC 7231, 6.6.5 StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6 StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1 StatusInsufficientStorage = 507 // RFC 4918, 11.5 StatusLoopDetected = 508 // RFC 5842, 7.2 StatusNotExtended = 510 // RFC 2774, 7 StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6 )
Status HTTP status codes as registered with IANA. See: http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const ( MIME_JSON = "application/json" MIME_XML = "application/xml" MIME_XML2 = "text/xml" MIME_HTML = "text/html" MIME_FORM = "application/x-www-form-urlencoded" MIME_MULTIPART_FORM = "multipart/form-data" )
MIME types used when doing request data reading and response data writing.
const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
TimeFormat is the time format to use when generating times in HTTP headers. It is like time.RFC1123 but hard-codes GMT as the time zone. The time being formatted must be in UTC for Format to generate the correct format.
For parsing this time format, see ParseTime.
Variables ¶
var ( ErrUnsupportedMediaType = NewHTTPError(StatusUnsupportedMediaType) ErrNotFound = NewHTTPError(StatusNotFound) ErrStatusBadRequest = NewHTTPError(StatusBadRequest) ErrForbidden = NewHTTPError(http.StatusForbidden) ErrMethodNotAllowed = NewHTTPError(StatusMethodNotAllowed) ErrStatusRequestEntityTooLarge = NewHTTPError(StatusRequestEntityTooLarge) ErrRendererNotRegistered = errors.New("renderer not registered") ErrInvalidRedirectCode = errors.New("invalid redirect status code") ErrCookieNotFound = errors.New("cookie not found") )
Errors
var ( // Methods lists all supported HTTP methods by Makross. Methods = []string{ CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, TRACE, } // FlashNow applies to current request. FlashNow bool )
var ( // DefaultPriority 默认优先级为0值 DefaultPriority int )
Functions ¶
func Config ¶
func Config() *ini.File
Config returns configuration convention object. It returns an empty object if there is no one available.
func GetAddress ¶
func GetAddress(args ...interface{}) string
func MethodNotAllowedHandler ¶
MethodNotAllowedHandler handles the situation when a request has matching route without matching HTTP method. In this case, the handler will respond with an Allow HTTP header listing the allowed HTTP methods. Otherwise, the handler will do nothing and let the next handler (usually a NotFoundHandler) to handle the problem.
func NotFoundHandler ¶
NotFoundHandler returns a 404 HTTP error indicating a request has no matching route.
func ReadFormData ¶
ReadFormData populates the data variable with the data from the given form values.
func SetConfig ¶
func SetConfig(source interface{}, others ...interface{}) (_ *ini.File, err error)
SetConfig sets data sources for configuration.
func StatusText ¶
StatusText returns a text for the HTTP status code. It returns the empty string if the code is unknown.
Types ¶
type Args ¶
type Args struct {
// contains filtered or unexported fields
}
func (*Args) MustFloat32 ¶
func (*Args) MustFloat64 ¶
func (*Args) ToSnakeCase ¶
type BindUnmarshaler ¶
type BindUnmarshaler interface { // UnmarshalParam decodes and assigns a value from an form or query param. UnmarshalParam(param string) error }
BindUnmarshaler is the interface used to wrap the UnmarshalParam method.
type Context ¶
type Context struct { Request *http.Request // the current request Response *Response // the response writer Localer Flash *Flash Session Sessioner FiltersMap *sync.Map //map[string][]byte // Not Global Filters, only in Context // contains filtered or unexported fields }
Context represents the contextual data and environment while processing an incoming HTTP request.
func (*Context) Abort ¶
Abort skips the rest of the handlers associated with the current route. Abort is normally used when a handler handles the request normally and wants to skip the rest of the handlers. If a handler wants to indicate an error condition, it should simply return the error without calling Abort.
func (*Context) AddActionHook ¶
AddActionHook (c *Context) 增加动作钩子
func (*Context) AddFilterHook ¶
AddFilterHook (c *Context) 增加过滤钩子
func (*Context) Attachment ¶
func (*Context) ContentTypeByExtension ¶
ContentTypeByExtension returns the MIME type associated with the file based on its extension. It returns `application/octet-stream` incase MIME type is not found.
func (*Context) DoActionHook ¶
DoActionHook (c *Context) 动作钩子
func (*Context) DoFilterHook ¶
DoFilterHook (c *Context) 执行过滤钩子
func (*Context) Form ¶
Form returns the first value for the named component of the query. Form reads the value from POST and PUT body parameters as well as URL query parameters. The form takes precedence over the latter. If key is not present, it returns the specified default value or an empty string.
func (*Context) Get ¶
Get returns the named data item previously registered with the context by calling Set. If the named data item cannot be found, nil will be returned.
func (*Context) GetCookies ¶
func (*Context) HandleError ¶
func (*Context) HasActionHook ¶
HasActionHook (c *Context) 是否有动作钩子
func (*Context) HasFilterHook ¶
HasFilterHook (c *Context) 是否有过滤钩子
func (*Context) HasQueuesMap ¶
HasQueuesMap (c *Context) Has QueuesMap
func (*Context) IsWebSocket ¶
func (*Context) JSONPretty ¶
func (*Context) NewHTTPError ¶
NewHTTPError creates a new HTTPError instance.
func (*Context) NewPriorityQueue ¶
func (c *Context) NewPriorityQueue() *prior.PriorityQueue
NewPriorityQueue New PriorityQueue
func (*Context) Next ¶
Next calls the rest of the handlers associated with the current route. If any of these handlers returns an error, Next will return the error and skip the following handlers. Next is normally used when a handler needs to do some postprocessing after the rest of the handlers are executed.
func (*Context) Param ¶
Param returns the named parameter value that is found in the URL path matching the current route. If the named parameter cannot be found, an empty string will be returned.
func (*Context) PostForm ¶
PostForm returns the first value for the named component from POST and PUT body parameters. If key is not present, it returns the specified default value or an empty string.
func (*Context) Query ¶
Query returns the first value for the named component of the URL query parameters. If key is not present, it returns the specified default value or an empty string.
func (*Context) QueryParam ¶
func (*Context) QueryParams ¶
func (*Context) QueryString ¶
func (*Context) Read ¶
Read populates the given struct variable with the data from the current request. If the request is NOT a GET request, it will check the "Content-Type" header and find a matching reader from DataReaders to read the request data. If there is no match or if the request is a GET request, it will use DefaultFormDataReader to read the request data.
func (*Context) RemoveActionHook ¶
RemoveActionHook (c *Context) 删除动作钩子
func (*Context) RemoveActionsHook ¶
func (c *Context) RemoveActionsHook()
RemoveActionsHook (c *Context) 删除所有动作钩子
func (*Context) RemoveFilterHook ¶
RemoveFilterHook (c *Context) 删除过滤钩子
func (*Context) RequestBody ¶
func (*Context) RequestHeader ¶
RequestHeader returns the request header's value accepts one parameter, the key of the header (string) returns string
func (*Context) RequestURI ¶
func (*Context) Reset ¶
func (c *Context) Reset(w http.ResponseWriter, r *http.Request)
Reset sets the request and response of the context and resets all other properties.
func (*Context) SendFile ¶
SendFile sends file for force-download to the client
Use this instead of ServeFile to 'force-download' bigger files to the client
func (*Context) ServeContent ¶
ServeContent serves content, headers are autoset receives three parameters, it's low-level function, instead you can use .ServeFile(string,bool)/SendFile(string,string)
You can define your own "Content-Type" header also, after this function call Doesn't implements resuming (by range), use ctx.SendFile instead
func (*Context) ServeFile ¶
ServeFile serves a view file, to send a file ( zip for example) to the client you should use the SendFile(serverfilename,clientfilename)
You can define your own "Content-Type" header also, after this function call This function doesn't implement resuming (by range), use ctx.SendFile/fasthttp.ServeFileUncompressed(ctx.RequestCtx,path)/fasthttpServeFile(ctx.RequestCtx,path) instead
Use it when you want to serve css/js/... files to the client, for bigger files and 'force-download' use the SendFile
func (*Context) Set ¶
Set stores the named data item in the context so that it can be retrieved later.
func (*Context) SetDataWriter ¶
func (c *Context) SetDataWriter(writer DataWriter)
SetDataWriter sets the data writer that will be used by Write().
func (*Context) SetHandler ¶
func (*Context) SetKontext ¶
func (*Context) SetPriorityQueueWith ¶
SetPriorityQueueWith c.makross.QueuesMap[key] = c.NewPriorityQueue()
func (*Context) URL ¶
URL creates a URL using the named route and the parameter values. The parameters should be given in the sequence of name1, value1, name2, value2, and so on. If a parameter in the route is not provided a value, the parameter token will remain in the resulting URL. Parameter values will be properly URL encoded. The method returns an empty string if the URL creation fails.
type DataReader ¶
type DataReader interface { // Read reads from the given HTTP request and populate the specified data. Read(*http.Request, interface{}) error }
DataReader is used by Context.Read() to read data from an HTTP request.
var ( // DataReaders lists all supported content types and the corresponding data readers. // Context.Read() will choose a matching reader from this list according to the "Content-Type" // header from the current request. // You may modify this variable to add new supported content types. DataReaders = map[string]DataReader{ MIME_FORM: &FormDataReader{}, MIME_MULTIPART_FORM: &FormDataReader{}, MIME_JSON: &JSONDataReader{}, MIME_XML: &XMLDataReader{}, MIME_XML2: &XMLDataReader{}, } // DefaultFormDataReader is the reader used when there is no matching reader in DataReaders // or if the current request is a GET request. DefaultFormDataReader DataReader = &FormDataReader{} )
type DataWriter ¶
type DataWriter interface { // SetHeader sets necessary response headers. SetHeader(http.ResponseWriter) // Write writes the given data into the response. Write(http.ResponseWriter, interface{}) error }
DataWriter is used by Context.Write() to write arbitrary data into an HTTP response.
var DefaultDataWriter DataWriter = &dataWriter{}
DefaultDataWriter writes the given data in an HTTP response. If the data is neither string nor byte array, it will use fmt.Fprint() to write it into the response.
type DefaultBinder ¶
type DefaultBinder struct{}
DefaultBinder is the default implementation of the Binder interface.
func (*DefaultBinder) Bind ¶
func (b *DefaultBinder) Bind(i interface{}, c *Context) (err error)
Bind implements the `Binder#Bind` function.
type Flash ¶
type FormDataReader ¶
type FormDataReader struct{}
FormDataReader reads the query parameters and request body as form data.
type HTTPError ¶
type HTTPError struct { Status int //`json:"status" xml:"status"` Message string //`json:"message" xml:"message"` }
Error contains the error information reported by calling Context.Error(). HTTPError represents an error that occurred while handling a request.
func NewHTTPError ¶
NewHTTPError creates a new HTTPError instance.
func (*HTTPError) StatusCode ¶
StatusCode returns the HTTP status code.
type Handler ¶
Handler is the function for handling HTTP requests.
func HTTPHandler ¶
HTTPHandler adapts a http.Handler into a makross.Handler.
func HTTPHandlerFunc ¶
func HTTPHandlerFunc(h http.HandlerFunc) Handler
HTTPHandlerFunc adapts a http.HandlerFunc into a makross.Handler.
func WrapHTTPHandler ¶
WrapHTTPHandler wraps `http.Handler` into `makross.Handler`.
type JSONDataReader ¶
type JSONDataReader struct{}
JSONDataReader reads the request body as JSON-formatted data.
type Makross ¶
type Makross struct { RouteGroup QueuesMap *sync.Map //map[string]*prior.PriorityQueue FiltersMap *sync.Map //map[string][]byte // Global Filters Server *http.Server // contains filtered or unexported fields }
Makross manages routes and dispatches HTTP requests to the handlers of the matching routes.
func (*Makross) AcquireContext ¶
AcquireContext returns an empty `Context` instance from the pool. You must return the context by calling `ReleaseContext()`.
func (*Makross) AddActionHook ¶
AddActionHook (m *Makross) 增加动作钩子
func (*Makross) AddFilterHook ¶
AddFilterHook (m *Makross) 增加过滤钩子
func (*Makross) DoActionHook ¶
DoActionHook (m *Makross) 动作钩子
func (*Makross) DoFilterHook ¶
DoFilterHook (m *Makross) 执行过滤钩子
func (*Makross) HandleError ¶
HandleError is the error handler for handling any unhandled errors.
func (*Makross) HasActionHook ¶
HasActionHook (m *Makross) 是否有动作钩子
func (*Makross) HasFilterHook ¶
HasFilterHook (m *Makross) 是否有过滤钩子
func (*Makross) HasQueuesMap ¶
HasQueuesMap (m *Makross) Has QueuesMap
func (*Makross) NewContext ¶
NewContext returns a Context instance.
func (*Makross) NewHTTPError ¶
NewHTTPError creates a new HTTPError instance.
func (*Makross) NewPriorityQueue ¶
func (m *Makross) NewPriorityQueue() *prior.PriorityQueue
NewPriorityQueue New PriorityQueue
func (*Makross) NotFound ¶
NotFound specifies the handlers that should be invoked when the makross cannot find any route matching a request. Note that the handlers registered via Use will be invoked first in this case.
func (*Makross) ReleaseContext ¶
ReleaseContext returns the `Context` instance back to the pool. You must call it after `AcquireContext()`.
func (*Makross) RemoveActionHook ¶
RemoveActionHook (m *Makross) 删除动作钩子
func (*Makross) RemoveActionsHook ¶
func (m *Makross) RemoveActionsHook()
RemoveActionsHook (m *Makross) 删除所有动作钩子
func (*Makross) RemoveFilterHook ¶
RemoveFilterHook (m *Makross) 删除过滤钩子
func (*Makross) Route ¶
Route returns the named route. Nil is returned if the named route cannot be found.
func (*Makross) ServeHTTP ¶
func (m *Makross) ServeHTTP(res http.ResponseWriter, req *http.Request)
ServeHTTP handles the HTTP request. It is required by http.Handler
func (*Makross) SetPriorityQueueWith ¶
SetPriorityQueueWith c.makross.QueuesMap[key] = c.NewPriorityQueue()
func (*Makross) SetRenderer ¶
SetRenderer registers an HTML template renderer. It's invoked by `Context#Render()`.
type RawStore ¶
type RawStore interface { // Set sets value to given key in session. Set(interface{}, interface{}) error // Get gets value by given key in session. Get(interface{}) interface{} // Delete deletes a key from session. Delete(interface{}) error // ID returns current session ID. ID() string // Release releases session resource and save data to provider. Release(*Context) error // Flush deletes all session data. Flush() error }
RawStore is the interface that operates the session data.
type Response ¶
type Response struct { Writer http.ResponseWriter Status int Size int64 Committed bool // contains filtered or unexported fields }
Response wraps an http.ResponseWriter and implements its interface to be used by an HTTP handler to construct an HTTP response. See: https://golang.org/pkg/net/http/#ResponseWriter
func NewResponse ¶
func NewResponse(w http.ResponseWriter, m *Makross) (r *Response)
NewResponse creates a new instance of Response.
func (*Response) CloseNotify ¶
CloseNotify implements the http.CloseNotifier interface to allow detecting when the underlying connection has gone away. This mechanism can be used to cancel long operations on the server if the client has disconnected before the response is ready. See http.CloseNotifier(https://golang.org/pkg/net/http/#CloseNotifier)
func (*Response) Flush ¶
func (r *Response) Flush()
Flush implements the http.Flusher interface to allow an HTTP handler to flush buffered data to the client. See http.Flusher(https://golang.org/pkg/net/http/#Flusher)
func (*Response) Header ¶
Header returns the header map for the writer that will be sent by WriteHeader. Changing the header after a call to WriteHeader (or Write) has no effect unless the modified headers were declared as trailers by setting the "Trailer" header before the call to WriteHeader (see example) To suppress implicit response headers, set their value to nil. Example: https://golang.org/pkg/net/http/#example_ResponseWriter_trailers
func (*Response) Hijack ¶
Hijack implements the http.Hijacker interface to allow an HTTP handler to take over the connection. See http.Hijacker(https://golang.org/pkg/net/http/#Hijacker)
func (*Response) WriteHeader ¶
WriteHeader sends an HTTP response header with status code. If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route represents a URL path pattern that can be used to match requested URLs.
func (*Route) Name ¶
Name sets the name of the route. This method will update the registration of the route in the makross as well.
func (*Route) Tags ¶
func (r *Route) Tags() []interface{}
Tags returns all custom data associated with the route.
func (*Route) To ¶
To adds the route to the makross with the given HTTP methods and handlers. Multiple HTTP methods should be separated by commas (without any surrounding spaces).
func (*Route) URL ¶
URL creates a URL using the current route and the given parameters. The parameters should be given in the sequence of name1, value1, name2, value2, and so on. If a parameter in the route is not provided a value, the parameter token will remain in the resulting URL. The method will perform URL encoding for all given parameter values.
type RouteGroup ¶
type RouteGroup struct {
// contains filtered or unexported fields
}
RouteGroup represents a group of routes that share the same path prefix.
func (*RouteGroup) Any ¶
func (rg *RouteGroup) Any(path string, handlers ...Handler) *Route
Any adds a route with the given route, handlers, and the HTTP methods as listed in makross.Methods.
func (*RouteGroup) Connect ¶
func (rg *RouteGroup) Connect(path string, handlers ...Handler) *Route
Connect adds a CONNECT route to the makross with the given route path and handlers.
func (*RouteGroup) Delete ¶
func (rg *RouteGroup) Delete(path string, handlers ...Handler) *Route
Delete adds a DELETE route to the makross with the given route path and handlers.
func (*RouteGroup) Get ¶
func (rg *RouteGroup) Get(path string, handlers ...Handler) *Route
Get adds a GET route to the makross with the given route path and handlers.
func (*RouteGroup) Group ¶
func (rg *RouteGroup) Group(prefix string, handlers ...Handler) *RouteGroup
Group creates a RouteGroup with the given route path prefix and handlers. The new group will combine the existing path prefix with the new one. If no handler is provided, the new group will inherit the handlers registered with the current group.
func (*RouteGroup) Head ¶
func (rg *RouteGroup) Head(path string, handlers ...Handler) *Route
Head adds a HEAD route to the makross with the given route path and handlers.
func (*RouteGroup) Options ¶
func (rg *RouteGroup) Options(path string, handlers ...Handler) *Route
Options adds an OPTIONS route to the makross with the given route path and handlers.
func (*RouteGroup) Patch ¶
func (rg *RouteGroup) Patch(path string, handlers ...Handler) *Route
Patch adds a PATCH route to the makross with the given route path and handlers.
func (*RouteGroup) Post ¶
func (rg *RouteGroup) Post(path string, handlers ...Handler) *Route
Post adds a POST route to the makross with the given route path and handlers.
func (*RouteGroup) Put ¶
func (rg *RouteGroup) Put(path string, handlers ...Handler) *Route
Put adds a PUT route to the makross with the given route path and handlers.
func (*RouteGroup) SetRenderer ¶
func (rg *RouteGroup) SetRenderer(r Renderer)
SetRenderer registers an HTML template renderer.
func (*RouteGroup) To ¶
func (rg *RouteGroup) To(methods, path string, handlers ...Handler) *Route
To adds a route to the makross with the given HTTP methods, route path, and handlers. Multiple HTTP methods should be separated by commas (without any surrounding spaces).
func (*RouteGroup) Trace ¶
func (rg *RouteGroup) Trace(path string, handlers ...Handler) *Route
Trace adds a TRACE route to the makross with the given route path and handlers.
func (*RouteGroup) Use ¶
func (rg *RouteGroup) Use(handlers ...Handler)
Use registers one or multiple handlers to the current route group. These handlers will be shared by all routes belong to this group and its subgroups.
type Sessioner ¶
type Sessioner interface { RawStore //---------------------------------------------// // Read returns raw session store by session ID. Read(string) (RawStore, error) // Destory deletes a session. Destory(*Context) error // RegenerateId regenerates a session store from old session ID to new one. RegenerateId(*Context) (RawStore, error) // Count counts and returns number of sessions. Count() int // GC calls GC to clean expired sessions. GC() }
Sessioner is the interface that contains all data for one session process with specific ID.
type XMLDataReader ¶
type XMLDataReader struct{}
XMLDataReader reads the request body as XML-formatted data.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package access provides an access logging handler for the ozzo makross package.
|
Package access provides an access logging handler for the ozzo makross package. |
Package auth provides a set of user authentication handlers for the makross.
|
Package auth provides a set of user authentication handlers for the makross. |
Package captcha a middleware that provides captcha service for Macross.
|
Package captcha a middleware that provides captcha service for Macross. |
Package content provides content negotiation handlers for the makross.
|
Package content provides content negotiation handlers for the makross. |
Package cors provides a handler for handling CORS.
|
Package cors provides a handler for handling CORS. |
Package fault provides a panic and error handler for the makross.
|
Package fault provides a panic and error handler for the makross. |
Package file provides handlers that serve static files for the ozzo makross package.
|
Package file provides handlers that serve static files for the ozzo makross package. |
Package i18n is a middleware that provides app Internationalization and Localization of Macross.
|
Package i18n is a middleware that provides app Internationalization and Localization of Macross. |
libraries
|
|
com
Package com is an open source project for commonly used functions for the Go programming language.
|
Package com is an open source project for commonly used functions for the Go programming language. |
femplate
Package femplate implements simple and fast template library.
|
Package femplate implements simple and fast template library. |
i18n
Package i18n is for app Internationalization and Localization.
|
Package i18n is for app Internationalization and Localization. |
i18n/ui18n
ui18n is a helper tool for Unknwon/i18n package.
|
ui18n is a helper tool for Unknwon/i18n package. |
ini.v1
Package ini provides INI file read and write functionality in Go.
|
Package ini provides INI file read and write functionality in Go. |