Documentation ¶
Index ¶
- Constants
- Variables
- func Bool(key interface{}, defaults ...interface{}) bool
- func CSS(key interface{}, defaults ...interface{}) template.CSS
- func CaptureTokens(pattern *regexp.Regexp, input string) *strings.Replacer
- func ContentTypeByExtension(name string) (t string)
- func DateTime(key interface{}, layouts ...string) time.Time
- func Decr(key interface{}, n int64, defaults ...interface{}) int64
- func DefaultSkipper(c Context) bool
- func Delete(key interface{})
- func Dump(m interface{}, args ...bool) (r string)
- func E(format string, args ...interface{}) error
- func Float32(key interface{}, defaults ...interface{}) float32
- func Float64(key interface{}, defaults ...interface{}) float64
- func FormNames(s string) []string
- func Get(key interface{}, defaults ...interface{}) interface{}
- func GetOk(key interface{}) (interface{}, bool)
- func GetOrSet(key, value interface{}) (actual interface{}, loaded bool)
- func HTML(key interface{}, defaults ...interface{}) template.HTML
- func HTMLAttr(key interface{}, defaults ...interface{}) template.HTMLAttr
- func HandlerName(h interface{}) string
- func HandlerPath(h interface{}) string
- func HandlerTmpl(handlerPath string) string
- func Has(key interface{}) bool
- func Incr(key interface{}, n int64, defaults ...interface{}) int64
- func Int(key interface{}, defaults ...interface{}) int
- func Int16(key interface{}, defaults ...interface{}) int16
- func Int32(key interface{}, defaults ...interface{}) int32
- func Int64(key interface{}, defaults ...interface{}) int64
- func Int8(key interface{}, defaults ...interface{}) int8
- func JS(key interface{}, defaults ...interface{}) template.JS
- func Methods() []string
- func NamedStructMap(e *Echo, m interface{}, data map[string][]string, topName string, ...) error
- func NewHost(name string) *host
- func Range(f func(key, value interface{}) bool)
- func Set(key, value interface{})
- func SetFormValue(f engine.URLValuer, fName string, index int, value interface{})
- func SetWorkDir(dir string)
- func Split(key interface{}, sep string, limit ...int) param.StringSlice
- func String(key interface{}, defaults ...interface{}) string
- func StructToForm(ctx Context, m interface{}, topName string, ...)
- func T(format string, args ...interface{}) string
- func Timestamp(key interface{}, defaults ...interface{}) time.Time
- func Trim(key interface{}, defaults ...interface{}) param.String
- func Uint(key interface{}, defaults ...interface{}) uint
- func Uint16(key interface{}, defaults ...interface{}) uint16
- func Uint32(key interface{}, defaults ...interface{}) uint32
- func Uint64(key interface{}, defaults ...interface{}) uint64
- func Uint8(key interface{}, defaults ...interface{}) uint8
- func Wd() string
- type Accept
- type Accepts
- type AsMiddleware
- type BaseTransaction
- type Binder
- type Closer
- type Context
- type ContextRegister
- type Cookie
- func (c *Cookie) Domain(p string) *Cookie
- func (c *Cookie) Expires(p int) *Cookie
- func (c *Cookie) HttpOnly(p bool) *Cookie
- func (c *Cookie) MaxAge(p int) *Cookie
- func (c *Cookie) Path(p string) *Cookie
- func (c *Cookie) SameSite(p string) *Cookie
- func (c *Cookie) Secure(p bool) *Cookie
- func (c *Cookie) Send(ctx Context)
- type CookieOptions
- type Cookier
- type Data
- type DebugSession
- func (n *DebugSession) AddFlash(value interface{}, args ...string) Sessioner
- func (n *DebugSession) Clear() Sessioner
- func (n *DebugSession) Delete(name string) Sessioner
- func (n *DebugSession) Flashes(args ...string) []interface{}
- func (n *DebugSession) Get(name string) interface{}
- func (n *DebugSession) ID() string
- func (n *DebugSession) Options(options SessionOptions) Sessioner
- func (n *DebugSession) Save() error
- func (n *DebugSession) Set(name string, value interface{}) Sessioner
- func (n *DebugSession) SetID(id string) Sessioner
- type DebugTransaction
- type Echo
- func (e *Echo) Add(method, path string, handler interface{}, middleware ...interface{}) *Route
- func (e *Echo) AddAcceptFormat(mime, format string) *Echo
- func (e *Echo) AddFormatRenderer(format string, renderer func(c Context, data interface{}) error) *Echo
- func (e *Echo) AddHandlerWrapper(funcs ...func(interface{}) Handler)
- func (e *Echo) AddMiddlewareWrapper(funcs ...func(interface{}) Middleware)
- func (e *Echo) Any(path string, h interface{}, middleware ...interface{}) IRouter
- func (e *Echo) AppendRouter(routes []*Route) *Echo
- func (e *Echo) Binder() Binder
- func (e *Echo) Clear(middleware ...interface{})
- func (e *Echo) Commit() *Echo
- func (e *Echo) Connect(path string, h interface{}, m ...interface{}) IRouter
- func (e *Echo) Debug() bool
- func (e *Echo) DefaultHTTPErrorHandler(err error, c Context)
- func (e *Echo) Delete(path string, h interface{}, m ...interface{}) IRouter
- func (e *Echo) Engine() engine.Engine
- func (e *Echo) File(path, file string)
- func (e *Echo) Get(path string, h interface{}, m ...interface{}) IRouter
- func (e *Echo) Group(prefix string, m ...interface{}) *Group
- func (e *Echo) HTTPErrorHandler() HTTPErrorHandler
- func (e *Echo) Head(path string, h interface{}, m ...interface{}) IRouter
- func (e *Echo) Host(name string, m ...interface{}) *Group
- func (e *Echo) Hosts() map[string]*Host
- func (e *Echo) Logger() logger.Logger
- func (e *Echo) Match(methods []string, path string, h interface{}, middleware ...interface{}) IRouter
- func (e *Echo) MetaHandler(m H, handler interface{}) Handler
- func (e *Echo) NamedRoutes() map[string][]int
- func (e *Echo) NewContext(req engine.Request, resp engine.Response) Context
- func (e *Echo) Options(path string, h interface{}, m ...interface{}) IRouter
- func (e *Echo) ParseHeaderAccept(on bool) *Echo
- func (e *Echo) Patch(path string, h interface{}, m ...interface{}) IRouter
- func (e *Echo) Post(path string, h interface{}, m ...interface{}) IRouter
- 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{}) IRouter
- func (e *Echo) RebuildRouter(args ...[]*Route) *Echo
- func (e *Echo) RemoveFormatRenderer(formats ...string) *Echo
- func (e *Echo) Renderer() Renderer
- func (e *Echo) Route(methods string, path string, h interface{}, middleware ...interface{}) IRouter
- func (e *Echo) Router() *Router
- func (e *Echo) Routes() []*Route
- func (e *Echo) Run(eng engine.Engine, handler ...engine.Handler) error
- func (e *Echo) ServeHTTP(req engine.Request, res engine.Response)
- func (e *Echo) SetAcceptFormats(acceptFormats map[string]string) *Echo
- func (e *Echo) SetBinder(b Binder)
- func (e *Echo) SetDebug(on bool)
- func (e *Echo) SetFormatRenderers(formatRenderers map[string]func(c Context, data interface{}) error) *Echo
- func (e *Echo) SetHTTPErrorHandler(h HTTPErrorHandler)
- func (e *Echo) SetHandlerWrapper(funcs ...func(interface{}) Handler)
- func (e *Echo) SetLogger(l logger.Logger)
- func (e *Echo) SetMiddlewareWrapper(funcs ...func(interface{}) Middleware)
- func (e *Echo) SetPrefix(prefix string) *Echo
- func (e *Echo) SetRenderer(r Renderer)
- func (e *Echo) Static(prefix, root string)
- func (e *Echo) Stop() error
- func (e *Echo) Trace(path string, h interface{}, m ...interface{}) IRouter
- 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 FieldNameFormatter
- type FormDataFilter
- type FromConversion
- type Group
- func (g *Group) Add(method, path string, h interface{}, middleware ...interface{}) *Route
- func (g *Group) Any(path string, h interface{}, middleware ...interface{}) IRouter
- func (g *Group) Connect(path string, h interface{}, m ...interface{}) IRouter
- func (g *Group) Delete(path string, h interface{}, m ...interface{}) IRouter
- func (g *Group) Echo() *Echo
- func (g *Group) File(path, file string)
- func (g *Group) Get(path string, h interface{}, m ...interface{}) IRouter
- func (g *Group) Group(prefix string, middleware ...interface{}) *Group
- func (g *Group) Head(path string, h interface{}, m ...interface{}) IRouter
- func (g *Group) Match(methods []string, path string, h interface{}, middleware ...interface{}) IRouter
- func (g *Group) MetaHandler(m H, handler interface{}) Handler
- func (g *Group) Options(path string, h interface{}, m ...interface{}) IRouter
- func (g *Group) Patch(path string, h interface{}, m ...interface{}) IRouter
- func (g *Group) Post(path string, h interface{}, m ...interface{}) IRouter
- 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{}) IRouter
- func (g *Group) Route(methods string, path string, h interface{}, middleware ...interface{}) IRouter
- func (g *Group) SetRenderer(r Renderer)
- func (g *Group) Static(prefix, root string)
- func (g *Group) Trace(path string, h interface{}, m ...interface{}) IRouter
- func (g *Group) URL(h interface{}, params ...interface{}) string
- func (g *Group) Use(middleware ...interface{})
- type H
- type HTTPError
- type HTTPErrorHandler
- type Handler
- type HandlerFunc
- type Host
- type ICore
- type IRouter
- type KV
- type KVData
- func (a *KVData) Add(k, v string) *KVData
- func (a *KVData) Delete(ks ...string) *KVData
- func (a *KVData) Get(k string) string
- func (a *KVData) Has(k string) bool
- func (a *KVData) Index(k string) []int
- func (a *KVData) Indexes() map[string][]int
- func (a *KVData) Reset() *KVData
- func (a *KVData) Set(k, v string) *KVData
- func (a *KVData) Slice() []*KV
- type KVList
- type Mapx
- func (m *Mapx) Add(name string, values []string) *Mapx
- func (m *Mapx) AsFlatSlice() []string
- func (m *Mapx) AsMap() map[string]interface{}
- func (m *Mapx) AsSlice() []interface{}
- func (m *Mapx) AsStore() Store
- func (m *Mapx) Clone() *Mapx
- func (m *Mapx) Get(names ...string) *Mapx
- func (m *Mapx) IsMap() bool
- func (m *Mapx) IsSlice() bool
- func (m *Mapx) Parse(data map[string][]string, keySkipper ...func(string) bool) *Mapx
- func (m *Mapx) Value(names ...string) string
- func (m *Mapx) ValueOk(names ...string) (string, bool)
- func (m *Mapx) Values(names ...string) []string
- func (m *Mapx) ValuesOk(names ...string) ([]string, bool)
- type Meta
- type MetaHandler
- 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 MiddlewareRegister
- type Name
- 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 NopTransaction
- type NopTranslate
- type NopValidation
- type PanicError
- func (p *PanicError) AddTrace(trace *Trace) *PanicError
- func (p *PanicError) Debug() bool
- func (p *PanicError) Error() string
- func (p *PanicError) ExtractSnippets(file string, curLineNum int, index int) error
- func (p *PanicError) HTML() template.HTML
- func (p *PanicError) JSONString() string
- func (p *PanicError) Parse(stackSizes ...int) *PanicError
- func (p *PanicError) SetDebug(on bool) *PanicError
- func (p *PanicError) SetError(err error) *PanicError
- func (p *PanicError) SetErrorString(errStr string) *PanicError
- func (p *PanicError) String() string
- type Prefixer
- type RawData
- func (d *RawData) Assign(key string, val interface{})
- func (d *RawData) Assignx(values *map[string]interface{})
- func (d *RawData) Error() string
- func (d *RawData) GetCode() State
- func (d *RawData) GetData() interface{}
- func (d *RawData) GetInfo() interface{}
- func (d *RawData) GetURL() string
- func (d *RawData) GetZone() interface{}
- func (d *RawData) Gets() (State, interface{}, interface{}, interface{})
- func (d *RawData) Reset() Data
- func (d *RawData) Set(code int, args ...interface{}) Data
- func (d *RawData) SetByMap(s Store) Data
- func (d *RawData) SetCode(code int) Data
- func (d *RawData) SetContext(ctx Context) Data
- func (d *RawData) SetData(data interface{}, args ...int) Data
- func (d *RawData) SetError(err error, args ...int) Data
- func (d *RawData) SetInfo(info interface{}, args ...int) Data
- func (d *RawData) SetTmplFuncs()
- func (d *RawData) SetURL(url string, args ...int) Data
- func (d *RawData) SetZone(zone interface{}) Data
- func (d *RawData) String() string
- type Renderer
- type RendererRegister
- type Route
- type RouteRegister
- type Router
- type Routes
- type SessionOptions
- type Sessioner
- type Skipper
- type Snippet
- type SnippetGroup
- type State
- type Status
- type Store
- type ToConversion
- type Trace
- type Transaction
- type Translator
- type URLBuilder
- type ValidateResult
- type Validation
- type Validator
- type ValidatorResult
- func (v *ValidatorResult) Error() error
- func (v *ValidatorResult) Field() string
- func (v *ValidatorResult) Ok() bool
- func (v *ValidatorResult) Raw() interface{}
- func (v *ValidatorResult) SetError(err error) ValidateResult
- func (v *ValidatorResult) SetField(field string) ValidateResult
- func (v *ValidatorResult) SetRaw(raw interface{}) ValidateResult
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" MIMEEventStream = "text/event-stream" CharsetUTF8 = "charset=utf-8" HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" HeaderAllow = "Allow" 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" HeaderXRequestID = "X-Request-ID" HeaderXRequestedWith = "X-Requested-With" HeaderServer = "Server" HeaderOrigin = "Origin" HeaderCacheControl = "Cache-Control" // 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" FilePathSeparator = string(filepath.Separator) )
const ( SnippetLineNumbers = 13 StackSize = 4 << 10 // 4 KB )
Variables ¶
var ( //DefaultNopFilter 默认过滤器(map->struct) DefaultNopFilter FormDataFilter = func(k string, v []string) (string, []string) { return k, v } //DefaultFieldNameFormatter 默认格式化函数(struct->form) DefaultFieldNameFormatter FieldNameFormatter = func(topName, fieldName string) string { var fName string if len(topName) == 0 { fName = fieldName } else { fName = topName + "." + fieldName } return fName } //LowerCaseFirstLetter 小写首字母(struct->form) LowerCaseFirstLetter FieldNameFormatter = func(topName, fieldName string) string { var fName string s := []rune(fieldName) if len(s) > 0 { s[0] = unicode.ToLower(s[0]) fieldName = string(s) } if len(topName) == 0 { fName = fieldName } else { fName = topName + "." + fieldName } return fName } //DateToTimestamp 日期时间转时间戳 DateToTimestamp = func(layouts ...string) FormDataFilter { layout := `2006-01-02` if len(layouts) > 0 && len(layouts[0]) > 0 { layout = layouts[0] } return func(k string, v []string) (string, []string) { if len(v) > 0 && len(v[0]) > 0 { t, e := time.Parse(layout, v[0]) if e != nil { log.Error(e) return k, []string{`0`} } return k, []string{fmt.Sprint(t.Unix())} } return k, []string{`0`} } } //TimestampToDate 时间戳转日期时间 TimestampToDate = func(layouts ...string) FormDataFilter { layout := `2006-01-02 15:04:05` if len(layouts) > 0 && len(layouts[0]) > 0 { layout = layouts[0] } return func(k string, v []string) (string, []string) { if len(v) > 0 && len(v[0]) > 0 { tsi := strings.SplitN(v[0], `.`, 2) var sec, nsec int64 switch len(tsi) { case 2: nsec = param.AsInt64(tsi[1]) fallthrough case 1: sec = param.AsInt64(tsi[0]) } t := time.Unix(sec, nsec) if t.IsZero() { return k, []string{``} } return k, []string{t.Format(layout)} } return k, v } } //JoinValues 组合数组为字符串 JoinValues = func(seperators ...string) FormDataFilter { sep := `,` if len(seperators) > 0 { sep = seperators[0] } return func(k string, v []string) (string, []string) { return k, []string{strings.Join(v, sep)} } } //SplitValues 拆分字符串为数组 SplitValues = func(seperators ...string) FormDataFilter { sep := `,` if len(seperators) > 0 { sep = seperators[0] } return func(k string, v []string) (string, []string) { if len(v) > 0 && len(v[0]) > 0 { v = strings.Split(v[0], sep) } return k, v } } )
var ( //States 状态码对应的文本 States = map[State]*Status{ -2: {`Non-Privileged`, http.StatusOK}, -1: {`Unauthenticated`, http.StatusOK}, 0: {`Failure`, http.StatusOK}, 1: {`Success`, http.StatusOK}, } //GetStatus 获取状态值 GetStatus = func(key State) (*Status, bool) { v, y := States[key] return v, y } )
var ( DefaultNopSession Sessioner = &NopSession{} DefaultDebugSession Sessioner = &DebugSession{} DefaultSession = DefaultNopSession DefaultSessionOptions = NewSessionOptions(`cookie`, `SID`) )
var ( ErrUnsupportedMediaType error = NewHTTPError(http.StatusUnsupportedMediaType) ErrNotFound error = NewHTTPError(http.StatusNotFound) ErrForbidden error = NewHTTPError(http.StatusForbidden) ErrStatusRequestEntityTooLarge error = NewHTTPError(http.StatusRequestEntityTooLarge) ErrMethodNotAllowed error = NewHTTPError(http.StatusMethodNotAllowed) ErrRendererNotRegistered = errors.New("renderer not registered") ErrInvalidRedirectCode = errors.New("invalid redirect status code") ErrNotFoundFileInput = errors.New("The specified name file input was not found") NotFoundHandler = HandlerFunc(func(c Context) error { return ErrNotFound }) MethodNotAllowedHandler = HandlerFunc(func(c Context) error { return ErrMethodNotAllowed }) )
var AsStore = param.AsStore
var (
DefaultCookieOptions = &CookieOptions{
Path: `/`,
}
)
var DefaultHTMLFilter = func(v string) (r string) {
return v
}
DefaultHTMLFilter html filter (`form_filter:"html"`)
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 HandlerTmpl ¶
func NamedStructMap ¶
func NamedStructMap(e *Echo, m interface{}, data map[string][]string, topName string, filters ...FormDataFilter) error
NamedStructMap 自动将map值映射到结构体
func SetFormValue ¶
func SetWorkDir ¶
func SetWorkDir(dir string)
func StructToForm ¶
func StructToForm(ctx Context, m interface{}, topName string, fieldNameFormatter FieldNameFormatter)
StructToForm 映射struct到form
Types ¶
type Accepts ¶
func NewAccepts ¶
type AsMiddleware ¶
func (AsMiddleware) Handle ¶
func (m AsMiddleware) Handle(h Handler) Handler
type BaseTransaction ¶
type BaseTransaction struct { Transaction // contains filtered or unexported fields }
func NewTransaction ¶
func NewTransaction(trans Transaction) *BaseTransaction
type Binder ¶
type Binder interface { Bind(interface{}, Context, ...FormDataFilter) error MustBind(interface{}, Context, ...FormDataFilter) error }
Binder is the interface that wraps the Bind method.
type Context ¶
type Context interface { context.Context events.Emitter SetEmitter(events.Emitter) //Transaction SetTransaction(t Transaction) Transaction() Transaction Begin() error Rollback() error Commit() error End(succeed bool) error //Standard Context StdContext() context.Context SetStdContext(context.Context) Validator SetValidator(Validator) Translator SetTranslator(Translator) Request() engine.Request Response() engine.Response Handle(Context) error Logger() logger.Logger Object() *xContext Echo() *Echo Route() *Route Reset(engine.Request, engine.Response) Path() string P(int, ...string) string Param(string, ...string) string // ParamNames returns path parameter names. ParamNames() []string ParamValues() []string SetParamValues(values ...string) // Host HostNames() []string HostValues() []string HostParam(string, ...string) string HostP(int, ...string) string // Queries returns the query parameters as map. It is an alias for `engine.URL#Query()`. Queries() map[string][]string QueryValues(string) []string QueryxValues(string) param.StringSlice Query(string, ...string) string Form(string, ...string) string FormValues(string) []string FormxValues(string) param.StringSlice // Forms returns the form parameters as map. It is an alias for `engine.Request#Form().All()`. Forms() map[string][]string // Param+ Px(int, ...string) param.String Paramx(string, ...string) param.String Queryx(string, ...string) param.String Formx(string, ...string) param.String // string to param.String Atop(string) param.String ToParamString(string) param.String ToStringSlice([]string) param.StringSlice Set(string, interface{}) Get(string, ...interface{}) interface{} Delete(...string) Stored() Store Internal() *param.SafeMap Bind(interface{}, ...FormDataFilter) error MustBind(interface{}, ...FormDataFilter) error Render(string, interface{}, ...int) error HTML(string, ...int) error String(string, ...int) error Blob([]byte, ...int) error JSON(interface{}, ...int) error JSONBlob([]byte, ...int) error JSONP(string, interface{}, ...int) error XML(interface{}, ...int) error XMLBlob([]byte, ...int) error Stream(func(io.Writer) bool) SSEvent(string, chan interface{}) error File(string, ...http.FileSystem) error Attachment(io.Reader, string, ...bool) error NoContent(...int) error Redirect(string, ...int) error Error(err error) SetCode(int) Code() int SetData(Data) Data() Data // 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{} PrintFuncs() //---------------- // Render //---------------- SetAuto(on bool) Context Fetch(string, interface{}) ([]byte, error) SetRenderer(Renderer) SetCookieOptions(*CookieOptions) CookieOptions() *CookieOptions NewCookie(string, string) *Cookie Cookie() Cookier GetCookie(string) string SetCookie(string, string, ...interface{}) SetSessionOptions(*SessionOptions) SessionOptions() *SessionOptions SetSessioner(Sessioner) Session() Sessioner Flash(...string) interface{} Header(string) string IsAjax() bool IsPjax() bool PjaxContainer() string Method() string Format() string SetFormat(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 Accept() *Accepts Protocol() string Site() string Scheme() string Domain() string Host() string Proxy() []string Referer() string Port() int RealIP() string HasAnyRequest() bool MapForm(i interface{}, names ...string) error MapData(i interface{}, data map[string][]string, names ...string) error SaveUploadedFile(fieldName string, saveAbsPath string, saveFileName ...string) (*multipart.FileHeader, error) SaveUploadedFileToWriter(string, io.Writer) (*multipart.FileHeader, error) //Multiple file upload SaveUploadedFiles(fieldName string, savePath func(*multipart.FileHeader) (string, error)) error SaveUploadedFilesToWriter(fieldName string, writer func(*multipart.FileHeader) (io.Writer, error)) error AddPreResponseHook(func() error) Context SetPreResponseHook(...func() error) Context // contains filtered or unexported methods }
Context represents context for the current request. It holds request and response objects, path parameters, data and registered handler.
type ContextRegister ¶
type ContextRegister interface {
SetContext(Context)
}
type Cookie ¶
type Cookie struct {
// contains filtered or unexported fields
}
Cookie 操作封装
type CookieOptions ¶
type CookieOptions struct { Prefix string // MaxAge=0 means no 'Max-Age' attribute specified. // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'. // MaxAge>0 means Max-Age attribute present and given in seconds. MaxAge int Path string Domain string Secure bool HttpOnly bool SameSite string // strict / lax }
CookieOptions cookie options
func (*CookieOptions) Clone ¶
func (c *CookieOptions) Clone() *CookieOptions
type Cookier ¶
type Cookier interface { Get(key string) string Set(key string, val string, args ...interface{}) Cookier }
Cookier interface
type Data ¶
type Data interface { Assign(key string, val interface{}) Assignx(values *map[string]interface{}) SetTmplFuncs() SetContext(ctx Context) Data String() string Set(code int, args ...interface{}) Data Reset() Data SetByMap(Store) Data SetError(err error, args ...int) Data SetCode(code int) Data SetURL(url string, args ...int) Data SetInfo(info interface{}, args ...int) Data SetZone(zone interface{}) Data SetData(data interface{}, args ...int) Data Gets() (code State, info interface{}, zone interface{}, data interface{}) GetCode() State GetInfo() interface{} GetZone() interface{} GetData() interface{} GetURL() string }
Data 响应数据
type DebugSession ¶
type DebugSession struct { }
func (*DebugSession) AddFlash ¶
func (n *DebugSession) AddFlash(value interface{}, args ...string) Sessioner
func (*DebugSession) Clear ¶
func (n *DebugSession) Clear() Sessioner
func (*DebugSession) Delete ¶
func (n *DebugSession) Delete(name string) Sessioner
func (*DebugSession) Flashes ¶
func (n *DebugSession) Flashes(args ...string) []interface{}
func (*DebugSession) Get ¶
func (n *DebugSession) Get(name string) interface{}
func (*DebugSession) ID ¶
func (n *DebugSession) ID() string
func (*DebugSession) Options ¶
func (n *DebugSession) Options(options SessionOptions) Sessioner
func (*DebugSession) Save ¶
func (n *DebugSession) Save() error
func (*DebugSession) Set ¶
func (n *DebugSession) Set(name string, value interface{}) Sessioner
func (*DebugSession) SetID ¶
func (n *DebugSession) SetID(id string) Sessioner
type DebugTransaction ¶
type DebugTransaction struct { }
type Echo ¶
type Echo struct { FuncMap map[string]interface{} RouteDebug bool MiddlewareDebug bool JSONPVarName string // contains filtered or unexported fields }
func NewWithContext ¶
func (*Echo) Add ¶
Add registers a new route for an HTTP method and path with matching handler in the router with optional route-level middleware.
func (*Echo) AddAcceptFormat ¶
func (*Echo) AddFormatRenderer ¶
func (*Echo) AddHandlerWrapper ¶
func (*Echo) AddMiddlewareWrapper ¶
func (e *Echo) AddMiddlewareWrapper(funcs ...func(interface{}) Middleware)
func (*Echo) AppendRouter ¶
AppendRouter append router
func (*Echo) DefaultHTTPErrorHandler ¶
DefaultHTTPErrorHandler invokes the default HTTP error handler.
func (*Echo) HTTPErrorHandler ¶
func (e *Echo) HTTPErrorHandler() HTTPErrorHandler
HTTPErrorHandler returns the HTTPErrorHandler
func (*Echo) Host ¶
Host creates a new router group for the provided host and optional host-level middleware.
func (*Echo) Match ¶
func (e *Echo) Match(methods []string, path string, h interface{}, middleware ...interface{}) IRouter
Match adds a route > handler to the router for multiple HTTP methods provided.
func (*Echo) MetaHandler ¶
MetaHandler Add meta information about endpoint
func (*Echo) NamedRoutes ¶
NamedRoutes returns the registered handler name.
func (*Echo) NewContext ¶
func (*Echo) ParseHeaderAccept ¶
func (*Echo) Pre ¶
func (e *Echo) Pre(middleware ...interface{})
Pre is an alias for `PreUse` function.
func (*Echo) PreUse ¶
func (e *Echo) PreUse(middleware ...interface{})
PreUse adds handler to the middleware chain.
func (*Echo) RebuildRouter ¶
RebuildRouter rebuild router
func (*Echo) RemoveFormatRenderer ¶
func (*Echo) SetAcceptFormats ¶
func (*Echo) SetFormatRenderers ¶
func (*Echo) SetHTTPErrorHandler ¶
func (e *Echo) SetHTTPErrorHandler(h HTTPErrorHandler)
SetHTTPErrorHandler registers a custom Echo.HTTPErrorHandler.
func (*Echo) SetHandlerWrapper ¶
func (*Echo) SetMiddlewareWrapper ¶
func (e *Echo) SetMiddlewareWrapper(funcs ...func(interface{}) Middleware)
func (*Echo) SetRenderer ¶
SetRenderer registers an HTML template renderer. It's invoked by Context.Render().
func (*Echo) Static ¶
Static registers a new route with path prefix to serve static files from the provided root directory.
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 FieldNameFormatter ¶
FieldNameFormatter 结构体字段值映射到表单时,结构体字段名称格式化处理
type FormDataFilter ¶
FormDataFilter 将map映射到结构体时,对名称和值的过滤处理,如果返回的名称为空,则跳过本字段
func ExcludeFieldName ¶
func ExcludeFieldName(fieldNames ...string) FormDataFilter
ExcludeFieldName 排除字段
func FormatFieldValue ¶
func FormatFieldValue(formatters map[string]FormDataFilter) FormDataFilter
FormatFieldValue 格式化字段值
func IncludeFieldName ¶
func IncludeFieldName(fieldNames ...string) FormDataFilter
IncludeFieldName 包含字段
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) MetaHandler ¶
MetaHandler Add meta information about endpoint
func (*Group) Pre ¶
func (g *Group) Pre(middleware ...interface{})
Pre is an alias for `PreUse` function.
func (*Group) SetRenderer ¶
type HTTPError ¶
func NewHTTPError ¶
type HTTPErrorHandler ¶
HTTPErrorHandler is a centralized HTTP error handler.
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
type ICore ¶
type ICore interface { RouteRegister MiddlewareRegister URLBuilder RendererRegister Prefixer }
type Mapx ¶
type Mapx struct { Map map[string]*Mapx `json:",omitempty"` Slice []*Mapx `json:",omitempty"` Val []string `json:",omitempty"` // contains filtered or unexported fields }
func (*Mapx) AsFlatSlice ¶
type MetaHandler ¶
type MetaHandler struct { Handler // contains filtered or unexported fields }
func (*MetaHandler) Meta ¶
func (m *MetaHandler) Meta() H
func (*MetaHandler) Name ¶
func (m *MetaHandler) Name() string
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.Middleware`.
func WrapMiddlewareFromStdHandleFunc ¶
func WrapMiddlewareFromStdHandleFunc(h func(http.ResponseWriter, *http.Request)) Middleware
WrapMiddlewareFromStdHandleFunc wrap `func(http.ResponseWriter, *http.Request)` into `echo.Middleware`.
func WrapMiddlewareFromStdHandleFuncd ¶
func WrapMiddlewareFromStdHandleFuncd(h func(http.ResponseWriter, *http.Request) error) Middleware
WrapMiddlewareFromStdHandleFuncd wrap `func(http.ResponseWriter, *http.Request)` into `echo.Middleware`.
func WrapMiddlewareFromStdHandler ¶
func WrapMiddlewareFromStdHandler(h http.Handler) Middleware
WrapMiddlewareFromStdHandler wrap `http.HandlerFunc` into `echo.Middleware`.
type MiddlewareFunc ¶
func (MiddlewareFunc) Handle ¶
func (m MiddlewareFunc) Handle(h Handler) Handler
type MiddlewareFuncd ¶
type MiddlewareFuncd func(Handler) HandlerFunc
func (MiddlewareFuncd) Handle ¶
func (m MiddlewareFuncd) Handle(h Handler) Handler
type MiddlewareRegister ¶
type MiddlewareRegister interface { Use(middleware ...interface{}) Pre(middleware ...interface{}) }
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 NopTransaction ¶
type NopTransaction struct { }
type NopTranslate ¶
type NopTranslate struct {
// contains filtered or unexported fields
}
func (*NopTranslate) E ¶
func (n *NopTranslate) E(format string, args ...interface{}) error
func (*NopTranslate) Lang ¶
func (n *NopTranslate) Lang() string
func (*NopTranslate) T ¶
func (n *NopTranslate) T(format string, args ...interface{}) string
type NopValidation ¶
type NopValidation struct { }
func (*NopValidation) Validate ¶
func (v *NopValidation) Validate(_ interface{}, _ ...string) ValidateResult
type PanicError ¶
type PanicError struct { Raw interface{} Traces []*Trace Snippets []*SnippetGroup // contains filtered or unexported fields }
func NewPanicError ¶
func NewPanicError(recovered interface{}, err error, debugAndDisableStackAll ...bool) *PanicError
func (*PanicError) AddTrace ¶
func (p *PanicError) AddTrace(trace *Trace) *PanicError
func (*PanicError) Debug ¶
func (p *PanicError) Debug() bool
func (*PanicError) Error ¶
func (p *PanicError) Error() string
func (*PanicError) ExtractSnippets ¶
func (p *PanicError) ExtractSnippets(file string, curLineNum int, index int) error
func (*PanicError) HTML ¶
func (p *PanicError) HTML() template.HTML
func (*PanicError) JSONString ¶
func (p *PanicError) JSONString() string
func (*PanicError) Parse ¶
func (p *PanicError) Parse(stackSizes ...int) *PanicError
func (*PanicError) SetDebug ¶
func (p *PanicError) SetDebug(on bool) *PanicError
func (*PanicError) SetError ¶
func (p *PanicError) SetError(err error) *PanicError
func (*PanicError) SetErrorString ¶
func (p *PanicError) SetErrorString(errStr string) *PanicError
func (*PanicError) String ¶
func (p *PanicError) String() string
type RawData ¶
type RawData struct { Code State State string `json:",omitempty" xml:",omitempty"` Info interface{} URL string `json:",omitempty" xml:",omitempty"` Zone interface{} `json:",omitempty" xml:",omitempty"` Data interface{} `json:",omitempty" xml:",omitempty"` // contains filtered or unexported fields }
type RendererRegister ¶
type RendererRegister interface {
SetRenderer(Renderer)
}
type Route ¶
type RouteRegister ¶
type RouteRegister interface { Group(prefix string, middleware ...interface{}) *Group Any(path string, h interface{}, middleware ...interface{}) IRouter Route(methods string, path string, h interface{}, middleware ...interface{}) IRouter Match(methods []string, path string, h interface{}, middleware ...interface{}) IRouter Connect(path string, h interface{}, m ...interface{}) IRouter Delete(path string, h interface{}, m ...interface{}) IRouter Get(path string, h interface{}, m ...interface{}) IRouter Head(path string, h interface{}, m ...interface{}) IRouter Options(path string, h interface{}, m ...interface{}) IRouter Patch(path string, h interface{}, m ...interface{}) IRouter Post(path string, h interface{}, m ...interface{}) IRouter Put(path string, h interface{}, m ...interface{}) IRouter Trace(path string, h interface{}, m ...interface{}) IRouter Static(prefix, root string) File(path, file string) }
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
type SessionOptions ¶
type SessionOptions struct { Engine string //Store Engine Name string //Session Name *CookieOptions }
SessionOptions stores configuration for a session or session store. Fields are a subset of http.Cookie fields.
func NewSessionOptions ¶
func NewSessionOptions(engine string, name string, args ...*CookieOptions) *SessionOptions
func (*SessionOptions) Clone ¶
func (s *SessionOptions) Clone() *SessionOptions
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{} // Save saves all sessions used during the current request. Save() error }
Sessioner Wraps thinly gorilla-session methods. Session stores the values and optional configuration for a session.
type Skipper ¶
Skipper defines a function to skip middleware. Returning true skips processing the middleware.
type SnippetGroup ¶
func (*SnippetGroup) String ¶
func (sg *SnippetGroup) String() string
func (*SnippetGroup) TableRow ¶
func (sg *SnippetGroup) TableRow() string
type ToConversion ¶
type ToConversion interface {
ToString() string
}
ToConversion a struct implements this interface can be convert from struct to template variable Not Implemented
type Transaction ¶
type Transaction interface { Begin(ctx context.Context) error Rollback(ctx context.Context) error Commit(ctx context.Context) error End(ctx context.Context, succeed bool) error }
var ( DefaultNopTransaction Transaction = &NopTransaction{} DefaultDebugTransaction Transaction = &DebugTransaction{} )
type Translator ¶
type Translator interface { T(format string, args ...interface{}) string E(format string, args ...interface{}) error Lang() string }
var DefaultNopTranslate Translator = &NopTranslate{language: `en`}
type URLBuilder ¶
type URLBuilder interface {
URL(interface{}, ...interface{}) string
}
type ValidateResult ¶
type ValidateResult interface { Ok() bool Error() error Field() string Raw() interface{} //setter SetError(error) ValidateResult SetField(string) ValidateResult SetRaw(interface{}) ValidateResult }
func NewValidateResult ¶
func NewValidateResult() ValidateResult
type Validation ¶
type Validation struct {
// contains filtered or unexported fields
}
func (*Validation) Validate ¶
func (v *Validation) Validate(i interface{}, args ...string) ValidateResult
Validate 此处支持两种用法: 1. Validate(表单字段名, 表单值, 验证规则名) 2. Validate(结构体实例, 要验证的结构体字段1,要验证的结构体字段2) Validate(结构体实例) 代表验证所有带“valid”标签的字段
type Validator ¶
type Validator interface {
Validate(i interface{}, args ...string) ValidateResult
}
Validator is the interface that wraps the Validate method.
var ( DefaultNopValidate Validator = &NopValidation{} ErrNoSetValidator = errors.New(`The validator is not set`) )
func NewValidation ¶
func NewValidation() Validator
type ValidatorResult ¶
type ValidatorResult struct {
// contains filtered or unexported fields
}
func (*ValidatorResult) Error ¶
func (v *ValidatorResult) Error() error
func (*ValidatorResult) Field ¶
func (v *ValidatorResult) Field() string
func (*ValidatorResult) Ok ¶
func (v *ValidatorResult) Ok() bool
func (*ValidatorResult) Raw ¶
func (v *ValidatorResult) Raw() interface{}
func (*ValidatorResult) SetError ¶
func (v *ValidatorResult) SetError(err error) ValidateResult
func (*ValidatorResult) SetField ¶
func (v *ValidatorResult) SetField(field string) ValidateResult
func (*ValidatorResult) SetRaw ¶
func (v *ValidatorResult) SetRaw(raw interface{}) ValidateResult
Source Files ¶
- binder.go
- constant.go
- context.go
- context_accept.go
- context_store.go
- context_x_base.go
- context_x_request.go
- context_x_response.go
- context_x_session.go
- context_x_store.go
- context_x_transaction.go
- cookie.go
- cookie_11.go
- data.go
- echo.go
- error.go
- group.go
- hashmap.go
- helper.go
- host.go
- meta.go
- middleware.go
- register.go
- router.go
- sessioner.go
- transaction.go
- translator.go
- validator.go
- variable.go
- wrapper.go
Directories ¶
Path | Synopsis |
---|---|
encoding
|
|
handler
|
|
mvc/static/minify
Package cssmin minifies CSS.
|
Package cssmin minifies CSS. |
ratelimit/config
Package config provides data structure to configure rate-limiter.
|
Package config provides data structure to configure rate-limiter. |
render/standard
* * 模板扩展 * @author swh <swh@admpub.com>
|
* * 模板扩展 * @author swh <swh@admpub.com> |