Documentation
¶
Overview ¶
Copyright 2016 Wenhui Shen <www.webx.top>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2016 Wenhui Shen <www.webx.top>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func ContentTypeByExtension(name string) (t string)
- func DefaultSkipper(c Context) bool
- func HandlerName(h interface{}) string
- func Methods() []string
- func NamedStructMap(e *Echo, m interface{}, data map[string][]string, topName string) error
- func SplitJSON(s string) ([]string, error)
- type Binder
- type Context
- type Cookie
- type CookieOptions
- type Cookier
- type Data
- type Echo
- func (e *Echo) Any(path string, h interface{}, middleware ...interface{})
- func (e *Echo) AppendRouter(routes []*Route)
- func (e *Echo) Binder() Binder
- func (e *Echo) Connect(path string, h interface{}, m ...interface{})
- func (e *Echo) Debug() bool
- func (e *Echo) DefaultHTTPErrorHandler(err error, c Context)
- func (e *Echo) Delete(path string, h interface{}, m ...interface{})
- func (e *Echo) Get(path string, h interface{}, m ...interface{})
- func (e *Echo) Group(prefix string, m ...interface{}) (g *Group)
- func (e *Echo) Head(path string, h interface{}, m ...interface{})
- func (e *Echo) Logger() logger.Logger
- func (e *Echo) Match(methods []string, path string, h interface{}, middleware ...interface{})
- func (e *Echo) MetaHandler(m H, handler interface{}) interface{}
- func (e *Echo) MetaMiddleware(m H, middleware interface{}) interface{}
- func (e *Echo) NamedRoutes() map[string][]int
- func (e *Echo) Options(path string, h interface{}, m ...interface{})
- func (e *Echo) Patch(path string, h interface{}, m ...interface{})
- func (e *Echo) Post(path string, h interface{}, m ...interface{})
- func (e *Echo) Pre(middleware ...interface{})
- func (e *Echo) PreUse(middleware ...interface{})
- func (e *Echo) Prefix() string
- func (e *Echo) Put(path string, h interface{}, m ...interface{})
- func (e *Echo) RebuildRouter(args ...[]*Route)
- func (e *Echo) Route(methods string, path string, h interface{}, middleware ...interface{})
- func (e *Echo) Router() *Router
- func (e *Echo) Routes() []*Route
- func (e *Echo) Run(eng engine.Engine)
- func (e *Echo) ServeHTTP(req engine.Request, res engine.Response)
- func (e *Echo) SetBinder(b Binder)
- func (e *Echo) SetDebug(on bool)
- func (e *Echo) SetHTTPErrorHandler(h HTTPErrorHandler)
- func (e *Echo) SetLogger(l logger.Logger)
- func (e *Echo) SetRenderer(r Renderer)
- func (e *Echo) Stop() error
- func (e *Echo) Trace(path string, h interface{}, m ...interface{})
- func (e *Echo) URI(handler interface{}, params ...interface{}) string
- func (e *Echo) URL(h interface{}, params ...interface{}) string
- func (e *Echo) Use(middleware ...interface{})
- func (e *Echo) ValidHandler(v interface{}) (h Handler)
- func (e *Echo) ValidMiddleware(v interface{}) (m Middleware)
- type FromConversion
- type Group
- func (g *Group) Any(path string, h interface{}, middleware ...interface{})
- func (g *Group) Connect(path string, h interface{}, m ...interface{})
- func (g *Group) Delete(path string, h interface{}, m ...interface{})
- func (g *Group) Get(path string, h interface{}, m ...interface{})
- func (g *Group) Group(prefix string, m ...interface{}) *Group
- func (g *Group) Head(path string, h interface{}, m ...interface{})
- func (g *Group) Match(methods []string, path string, h interface{}, middleware ...interface{})
- func (g *Group) Options(path string, h interface{}, m ...interface{})
- func (g *Group) Patch(path string, h interface{}, m ...interface{})
- func (g *Group) Post(path string, h interface{}, m ...interface{})
- func (g *Group) Pre(middleware ...interface{})
- func (g *Group) PreUse(middleware ...interface{})
- func (g *Group) Prefix() string
- func (g *Group) Put(path string, h interface{}, m ...interface{})
- func (g *Group) Route(methods string, path string, h interface{}, middleware ...interface{})
- func (g *Group) SetRenderer(r Renderer)
- func (g *Group) Trace(path string, h interface{}, m ...interface{})
- func (g *Group) URL(h interface{}, params ...interface{}) string
- func (g *Group) Use(middleware ...interface{})
- type H
- type HTTPError
- type HTTPErrorHandler
- type HandleNamer
- type Handler
- type HandlerFunc
- type Middleware
- func WrapMiddleware(m interface{}) Middleware
- func WrapMiddlewareFromHandler(h HandlerFunc) Middleware
- func WrapMiddlewareFromStdHandleFunc(h func(http.ResponseWriter, *http.Request)) Middleware
- func WrapMiddlewareFromStdHandleFuncd(h func(http.ResponseWriter, *http.Request) error) Middleware
- func WrapMiddlewareFromStdHandler(h http.Handler) Middleware
- type MiddlewareFunc
- type MiddlewareFuncd
- type NopSession
- func (n *NopSession) AddFlash(_ interface{}, _ ...string) Sessioner
- func (n *NopSession) Clear() Sessioner
- func (n *NopSession) Delete(name string) Sessioner
- func (n *NopSession) Flashes(_ ...string) []interface{}
- func (n *NopSession) Get(name string) interface{}
- func (n *NopSession) Id() string
- func (n *NopSession) Options(_ SessionOptions) Sessioner
- func (n *NopSession) Save() error
- func (n *NopSession) Set(name string, value interface{}) Sessioner
- func (n *NopSession) SetId(id string) Sessioner
- type NopTranslate
- type Renderer
- type Route
- type Router
- type SessionOptions
- type Sessioner
- type Skipper
- type ToConversion
- type Translator
- type Validator
Constants ¶
const ( // CONNECT HTTP method CONNECT = "CONNECT" // DELETE HTTP method DELETE = "DELETE" // GET HTTP method GET = "GET" // HEAD HTTP method HEAD = "HEAD" // OPTIONS HTTP method OPTIONS = "OPTIONS" // PATCH HTTP method PATCH = "PATCH" // POST HTTP method POST = "POST" // PUT HTTP method PUT = "PUT" // TRACE HTTP method TRACE = "TRACE" MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + CharsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + CharsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + 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" CharsetUTF8 = "charset=utf-8" HeaderAcceptEncoding = "Accept-Encoding" HeaderAuthorization = "Authorization" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderIfModifiedSince = "If-Modified-Since" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXForwardedFor = "X-Forwarded-For" HeaderXRealIP = "X-Real-IP" HeaderServer = "Server" HeaderOrigin = "Origin" 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" )
Variables ¶
var ( ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType) ErrNotFound = NewHTTPError(http.StatusNotFound) ErrStatusRequestEntityTooLarge = NewHTTPError(http.StatusRequestEntityTooLarge) ErrMethodNotAllowed = NewHTTPError(http.StatusMethodNotAllowed) ErrRendererNotRegistered = errors.New("renderer not registered") ErrInvalidRedirectCode = errors.New("invalid redirect status code") NotFoundHandler = HandlerFunc(func(c Context) error { return ErrNotFound }) MethodNotAllowedHandler = HandlerFunc(func(c Context) error { return ErrMethodNotAllowed }) )
var DefaultHtmlFilter = func(v string) (r string) {
return v
}
Functions ¶
func 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 DefaultSkipper ¶
defaultSkipper returns false which processes the middleware.
func HandlerName ¶
func HandlerName(h interface{}) string
func NamedStructMap ¶
Types ¶
type Context ¶
type Context interface {
context.Context
Translator
Request() engine.Request
Response() engine.Response
Path() string
P(int) string
Param(string) string
// ParamNames returns path parameter names.
ParamNames() []string
SetParamNames(...string)
ParamValues() []string
SetParamValues(values ...string)
// Queries returns the query parameters as map. It is an alias for `engine.URL#Query()`.
Queries() map[string][]string
QueryValues(string) []string
Query(string) string
Form(string) string
FormValues(string) []string
// Forms returns the form parameters as map. It is an alias for `engine.Request#Form().All()`.
Forms() map[string][]string
Set(string, interface{})
Get(string) interface{}
Stored() store
Bind(interface{}) error
MustBind(interface{}) error
Render(string, interface{}, ...int) error
HTML(string, ...int) error
String(string, ...int) error
JSON(interface{}, ...int) error
JSONBlob([]byte, ...int) error
JSONP(string, interface{}, ...int) error
XML(interface{}, ...int) error
XMLBlob([]byte, ...int) error
File(string) error
Attachment(io.ReadSeeker, string) error
NoContent(...int) error
Redirect(string, ...int) error
Error(err error)
Handle(Context) error
Logger() logger.Logger
Object() *xContext
Echo() *Echo
// ServeContent sends static content from `io.Reader` and handles caching
// via `If-Modified-Since` request header. It automatically sets `Content-Type`
// and `Last-Modified` response headers.
ServeContent(io.ReadSeeker, string, time.Time) error
SetFunc(string, interface{})
GetFunc(string) interface{}
ResetFuncs(map[string]interface{})
Funcs() map[string]interface{}
Reset(engine.Request, engine.Response)
Fetch(string, interface{}) ([]byte, error)
SetRenderer(Renderer)
// Cookie
SetCookieOptions(*CookieOptions)
CookieOptions() *CookieOptions
NewCookie(string, string) *Cookie
Cookie() Cookier
GetCookie(string) string
SetCookie(string, string, ...interface{})
SetSessioner(Sessioner)
Session() Sessioner
Flash(string) interface{}
//with type action
Px(int) param.String
Paramx(string) param.String
Queryx(string) param.String
Formx(string) param.String
//string to param.String
Atop(string) param.String
SetTranslator(Translator)
Header(string) string
IsAjax() bool
Method() string
Format() string
IsPost() bool
IsGet() bool
IsPut() bool
IsDel() bool
IsHead() bool
IsPatch() bool
IsOptions() bool
IsSecure() bool
IsWebsocket() bool
IsUpload() bool
ResolveContentType() string
WithFormatExtension(bool)
ResolveFormat() string
Protocol() string
Site() string
Scheme() string
Domain() string
Host() string
Proxy() []string
Referer() string
Port() int
SetCode(int)
Code() int
NewData(...interface{}) *Data
}
Context represents context for the current request. It holds request and response objects, path parameters, data and registered handler.
type CookieOptions ¶
type Cookier ¶
func NewCookier ¶
type Data ¶
type Data struct {
Code int
Info interface{}
Zone interface{} `json:",omitempty" xml:",omitempty"`
Data interface{} `json:",omitempty" xml:",omitempty"`
}
type Echo ¶
type Echo struct {
HandlerWrapper func(interface{}) Handler
MiddlewareWrapper func(interface{}) Middleware
FuncMap map[string]interface{}
// contains filtered or unexported fields
}
func NewWithContext ¶
func (*Echo) DefaultHTTPErrorHandler ¶
DefaultHTTPErrorHandler invokes the default HTTP error handler.
func (*Echo) MetaHandler ¶
Add meta information about endpoint
func (*Echo) MetaMiddleware ¶
Add meta information about endpoint
func (*Echo) NamedRoutes ¶
NamedRoutes returns the registered handler name.
func (*Echo) PreUse ¶
func (e *Echo) PreUse(middleware ...interface{})
PreUse adds handler to the middleware chain.
func (*Echo) RebuildRouter ¶
RebuildRouter rebuild router
func (*Echo) SetHTTPErrorHandler ¶
func (e *Echo) SetHTTPErrorHandler(h HTTPErrorHandler)
SetHTTPErrorHandler registers a custom Echo.HTTPErrorHandler.
func (*Echo) SetRenderer ¶
SetRenderer registers an HTML template renderer. It's invoked by Context.Render().
func (*Echo) Use ¶
func (e *Echo) Use(middleware ...interface{})
Use adds handler to the middleware chain.
func (*Echo) ValidHandler ¶
func (*Echo) ValidMiddleware ¶
func (e *Echo) ValidMiddleware(v interface{}) (m Middleware)
type FromConversion ¶
FromConversion a struct implements this interface can be convert from request param to a struct
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func (*Group) SetRenderer ¶
type H ¶
type H map[string]interface{}
func (H) MarshalXML ¶
MarshalXML allows type H to be used with xml.Marshal
type HTTPError ¶
func NewHTTPError ¶
type HTTPErrorHandler ¶
HTTPErrorHandler is a centralized HTTP error handler.
type HandleNamer ¶
type HandleNamer interface {
HandleName() string
}
type Handler ¶
func WrapHandler ¶
func WrapHandler(h interface{}) Handler
WrapHandler wrap `interface{}` into `echo.Handler`.
type HandlerFunc ¶
func (HandlerFunc) Handle ¶
func (h HandlerFunc) Handle(c Context) error
func (HandlerFunc) SetMeta ¶
func (h HandlerFunc) SetMeta(e *Echo, meta H) HandlerFunc
type Middleware ¶
func WrapMiddleware ¶
func WrapMiddleware(m interface{}) Middleware
WrapMiddleware wrap `interface{}` into `echo.Middleware`.
func WrapMiddlewareFromHandler ¶
func WrapMiddlewareFromHandler(h HandlerFunc) Middleware
WrapMiddlewareFromHandler wrap `echo.HandlerFunc` into `echo.MiddlewareFunc`.
func WrapMiddlewareFromStdHandleFunc ¶
func WrapMiddlewareFromStdHandleFunc(h func(http.ResponseWriter, *http.Request)) Middleware
func WrapMiddlewareFromStdHandleFuncd ¶
func WrapMiddlewareFromStdHandleFuncd(h func(http.ResponseWriter, *http.Request) error) Middleware
func WrapMiddlewareFromStdHandler ¶
func WrapMiddlewareFromStdHandler(h http.Handler) Middleware
type MiddlewareFunc ¶
func (MiddlewareFunc) Handle ¶
func (m MiddlewareFunc) Handle(h Handler) Handler
func (MiddlewareFunc) SetMeta ¶
func (m MiddlewareFunc) SetMeta(e *Echo, meta H) MiddlewareFunc
type MiddlewareFuncd ¶
type MiddlewareFuncd func(Handler) HandlerFunc
func (MiddlewareFuncd) Handle ¶
func (m MiddlewareFuncd) Handle(h Handler) Handler
func (MiddlewareFuncd) SetMeta ¶
func (m MiddlewareFuncd) SetMeta(e *Echo, meta H) MiddlewareFuncd
type NopSession ¶
type NopSession struct {
}
func (*NopSession) AddFlash ¶
func (n *NopSession) AddFlash(_ interface{}, _ ...string) Sessioner
func (*NopSession) Clear ¶
func (n *NopSession) Clear() Sessioner
func (*NopSession) Delete ¶
func (n *NopSession) Delete(name string) Sessioner
func (*NopSession) Flashes ¶
func (n *NopSession) Flashes(_ ...string) []interface{}
func (*NopSession) Get ¶
func (n *NopSession) Get(name string) interface{}
func (*NopSession) Id ¶
func (n *NopSession) Id() string
func (*NopSession) Options ¶
func (n *NopSession) Options(_ SessionOptions) Sessioner
func (*NopSession) Save ¶
func (n *NopSession) Save() error
func (*NopSession) Set ¶
func (n *NopSession) Set(name string, value interface{}) Sessioner
func (*NopSession) SetId ¶
func (n *NopSession) SetId(id string) Sessioner
type NopTranslate ¶
type NopTranslate struct {
// contains filtered or unexported fields
}
func (*NopTranslate) Lang ¶
func (n *NopTranslate) Lang() string
func (*NopTranslate) T ¶
func (n *NopTranslate) T(format string, args ...interface{}) string
type SessionOptions ¶
type SessionOptions struct {
Engine string //Store Engine
Name string //Session Name
*CookieOptions
}
Options stores configuration for a session or session store. Fields are a subset of http.Cookie fields.
type Sessioner ¶
type Sessioner interface {
// Get returns the session value associated to the given key.
Get(key string) interface{}
// Set sets the session value associated to the given key.
Set(key string, val interface{}) Sessioner
SetId(id string) Sessioner
Id() string
// Delete removes the session value associated to the given key.
Delete(key string) Sessioner
// Clear deletes all values in the session.
Clear() Sessioner
// AddFlash adds a flash message to the session.
// A single variadic argument is accepted, and it is optional: it defines the flash key.
// If not defined "_flash" is used by default.
AddFlash(value interface{}, vars ...string) Sessioner
// Flashes returns a slice of flash messages from the session.
// A single variadic argument is accepted, and it is optional: it defines the flash key.
// If not defined "_flash" is used by default.
Flashes(vars ...string) []interface{}
Options(SessionOptions) Sessioner
// Save saves all sessions used during the current request.
Save() error
}
Wraps thinly gorilla-session methods. Session stores the values and optional configuration for a session.
var DefaultNopSession Sessioner = &NopSession{}
type Skipper ¶
Skipper defines a function to skip middleware. Returning true skips processing the middleware.
type ToConversion ¶
type ToConversion interface {
ToString() string
}
ToConversion a struct implements this interface can be convert from struct to template variable Not Implemented
type Translator ¶
var DefaultNopTranslate Translator = &NopTranslate{language: `en`}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
handler
|
|
|
oauth2/example
command
|
|
|
sockjs/example
command
|
|
|
websocket/example
command
|
|
|
markdown/example
command
|
|
|
ratelimit/config
Package config provides data structure to configure rate-limiter.
|
Package config provides data structure to configure rate-limiter. |
|
ratelimit/errors
Package errors provide data structure for errors.
|
Package errors provide data structure for errors. |
|
ratelimit/test
command
|
|
|
render/example
command
|
|
|
render/pongo2/test
command
|
|
|
render/standard
* * 模板扩展 * @author swh <swh@admpub.com>
|
* * 模板扩展 * @author swh <swh@admpub.com> |
|
render/standard/test
command
|
|