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 Clear(old []interface{}, clears ...interface{}) []interface{}
- func ContentTypeByExtension(name string) (t string)
- func CookieExpires(stdCookie *http.Cookie, expires time.Time)
- func CookieMaxAge(stdCookie *http.Cookie, p int)
- func CookieSameSite(stdCookie *http.Cookie, p string)
- func CopyCookieOptions(from *http.Cookie, to *http.Cookie)
- 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{}, printOrNot ...bool) (r string)
- func E(format string, args ...interface{}) error
- func Events() map[string]events.Dispatcher
- func Fire(e interface{}, mode int, context ...H) error
- func FlatStructToForm(ctx Context, m interface{}, topName string, ...)
- 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 HasEvent(name string) 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 LogIf(err error, types ...string)
- func Methods() []string
- func NamedStructMap(e *Echo, m interface{}, data map[string][]string, topName string, ...) error
- func NewCookie(key, value string, opt *CookieOptions) *http.Cookie
- func NewHost(name string) *host
- func Off(name string)
- func On(name string, cb func(H) error, onErrorDie ...bool)
- func PanicIf(err error)
- func Range(f func(key, value interface{}) bool)
- func SafeGetFieldByName(parentT reflect.Type, parentV reflect.Value, name string, value reflect.Value) (v reflect.Value)
- 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 TranslateStringer(t Translator, args ...interface{}) param.Stringer
- func Trim(key interface{}, defaults ...interface{}) param.String
- func URLDecode(encoded string, rfc ...bool) (string, error)
- func URLEncode(s string, rfc ...bool) 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 CookieOptions
- type Cookier
- type Data
- type DebugSession
- func (n *DebugSession) AddFlash(value interface{}, args ...string) Sessioner
- func (n *DebugSession) AddPreSaveHook(_ func(Context) error)
- 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) MustID() 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
- func (n *DebugSession) SetPreSaveHook(_ ...func(Context) error)
- 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) ClearPre(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{}, requests ...RequestValidator) 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) 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) Reset() *Echo
- 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) SetFormSliceMaxIndex(max int) *Echo
- 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) SetValidator(validator Validator) *Echo
- func (e *Echo) Shutdown(ctx context.Context) error
- 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) TypeHost(alias string, args ...interface{}) (r TypeHost)
- 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 Error
- func (e *Error) Cause() error
- func (e *Error) Delete(keys ...string) *Error
- func (e *Error) Error() string
- func (e *Error) ErrorCode() int
- func (e *Error) Set(key string, value interface{}) *Error
- func (e *Error) SetError(err error) *Error
- func (e *Error) SetZone(zone string) *Error
- func (e *Error) Unwrap() error
- type FieldNameFormatter
- type FormDataFilter
- type FromConversion
- type Group
- func (g *Group) Add(method, path string, h interface{}, middleware ...interface{}) *Route
- func (g *Group) Alias(alias string) Hoster
- 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{}, requests ...RequestValidator) 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) 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) SetAlias(alias string) *Group
- 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 Hoster
- type ICore
- type IRouter
- type KV
- func (a *KV) Fn() func(context.Context) interface{}
- func (a *KV) SetFn(fn func(context.Context) interface{}) *KV
- func (a *KV) SetH(h H) *KV
- func (a *KV) SetHKV(k string, v interface{}) *KV
- func (a *KV) SetK(k string) *KV
- func (a *KV) SetKV(k, v string) *KV
- func (a *KV) SetV(v string) *KV
- func (a *KV) SetX(x interface{}) *KV
- type KVData
- func (a *KVData) Add(k, v string) *KVData
- func (a *KVData) AddItem(item *KV) *KVData
- func (a *KVData) Delete(ks ...string) *KVData
- func (a *KVData) Get(k string, defaults ...string) string
- func (a *KVData) GetItem(k string, defaults ...func() *KV) *KV
- func (a *KVData) Has(k string) bool
- func (a *KVData) Index(k string) []int
- func (a *KVData) Indexes() map[string][]int
- func (a *KVData) Keys() []string
- func (a *KVData) Reset() *KVData
- func (a *KVData) Set(k, v string) *KVData
- func (a *KVData) SetItem(item *KV) *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 MetaValidator
- 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) AddPreSaveHook(_ func(Context) error)
- 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) MustID() 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
- func (n *NopSession) SetPreSaveHook(_ ...func(Context) error)
- 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) Error() string
- func (d *RawData) GetCode() pkgCode.Code
- func (d *RawData) GetData() interface{}
- func (d *RawData) GetInfo() interface{}
- func (d *RawData) GetURL() string
- func (d *RawData) GetZone() interface{}
- func (d *RawData) Gets() (pkgCode.Code, interface{}, interface{}, interface{})
- func (d *RawData) JSON(codes ...int) error
- func (d *RawData) JSONP(callback string, codes ...int) error
- 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
- func (d *RawData) XML(codes ...int) error
- type Renderer
- type RendererRegister
- type RequestValidator
- type Route
- func (r *Route) Bool(name string, defaults ...interface{}) bool
- func (r *Route) Float32(name string, defaults ...interface{}) float32
- func (r *Route) Float64(name string, defaults ...interface{}) float64
- func (r *Route) Get(name string, defaults ...interface{}) interface{}
- func (r *Route) GetStore(names ...string) H
- func (r *Route) Int(name string, defaults ...interface{}) int
- func (r *Route) Int32(name string, defaults ...interface{}) int32
- func (r *Route) Int64(name string, defaults ...interface{}) int64
- func (r *Route) IsZero() bool
- func (r *Route) MakeURI(params ...interface{}) (uri string)
- func (r *Route) SetName(name string) IRouter
- func (r *Route) String(name string, defaults ...interface{}) string
- func (r *Route) Uint(name string, defaults ...interface{}) uint
- func (r *Route) Uint32(name string, defaults ...interface{}) uint32
- func (r *Route) Uint64(name string, defaults ...interface{}) uint64
- type RouteRegister
- type Router
- type Routes
- type SessionOptions
- type Sessioner
- type Skipper
- type Snippet
- type SnippetGroup
- type Store
- type ToConversion
- type Trace
- type Transaction
- type Translator
- type TypeHost
- 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) // Content Type ContentTypeHTML = "html" ContentTypeJSON = "json" ContentTypeJSONP = "jsonp" ContentTypeXML = "xml" ContentTypeText = "text" )
const ( SnippetLineNumbers = 13 StackSize = 4 << 10 // 4 KB )
Variables ¶
var ( ErrBreak = errors.New("[BREAK]") ErrContinue = errors.New("[CONTINUE]") ErrExit = errors.New("[EXIT]") ErrReturn = errors.New("[RETURN]") ErrSliceIndexTooLarge = errors.New("The slice index value of the form field is too large") )
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.ParseInLocation(layout, v[0], time.Local) 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 } } TimestampStringer = param.TimestampStringer DateTimeStringer = param.DateTimeStringer WhitespaceStringer = param.WhitespaceStringer Ignored = param.Ignored )
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 }) StringerMapStart = param.StringerMapStart StoreStart = param.StoreStart HStart = param.StoreStart )
var ( DefaultAcceptFormats = map[string]string{ MIMEApplicationJSON: ContentTypeJSON, `text/javascript`: ContentTypeJSON, MIMEApplicationJavaScript: ContentTypeJSON, MIMEApplicationXML: ContentTypeXML, `text/xml`: ContentTypeXML, MIMETextPlain: ContentTypeText, `*/*`: ContentTypeHTML, `application/xhtml`: ContentTypeHTML, MIMETextHTML: ContentTypeHTML, `*`: ContentTypeHTML, } DefaultFormatRenderers = map[string]func(c Context, data interface{}) error{ ContentTypeJSON: func(c Context, data interface{}) error { return c.JSON(c.Data()) }, ContentTypeJSONP: func(c Context, data interface{}) error { return c.JSONP(c.Query(c.Echo().JSONPVarName), c.Data()) }, ContentTypeXML: func(c Context, data interface{}) error { return c.XML(c.Data()) }, ContentTypeText: func(c Context, data interface{}) error { return c.String(fmt.Sprint(data)) }, } DefaultBinderDecoders = map[string]func(interface{}, Context, ...FormDataFilter) error{ MIMEApplicationJSON: func(i interface{}, ctx Context, filter ...FormDataFilter) error { body := ctx.Request().Body() if body == nil { return NewHTTPError(http.StatusBadRequest, "Request body can't be nil") } defer body.Close() err := json.NewDecoder(body).Decode(i) if err != nil { if ute, ok := err.(*stdJSON.UnmarshalTypeError); ok { return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unmarshal type error: expected=%v, got=%v, field=%v, offset=%v", ute.Type, ute.Value, ute.Field, ute.Offset)).SetRaw(err) } if se, ok := err.(*stdJSON.SyntaxError); ok { return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Syntax error: offset=%v, error=%v", se.Offset, se.Error())).SetRaw(err) } return NewHTTPError(http.StatusBadRequest, err.Error()).SetRaw(err) } return err }, MIMEApplicationXML: func(i interface{}, ctx Context, filter ...FormDataFilter) error { body := ctx.Request().Body() if body == nil { return NewHTTPError(http.StatusBadRequest, "Request body can't be nil") } defer body.Close() err := xml.NewDecoder(body).Decode(i) if err != nil { if ute, ok := err.(*xml.UnsupportedTypeError); ok { return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unsupported type error: type=%v, error=%v", ute.Type, ute.Error())).SetRaw(err) } if se, ok := err.(*xml.SyntaxError); ok { return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Syntax error: line=%v, error=%v", se.Line, se.Error())).SetRaw(err) } return NewHTTPError(http.StatusBadRequest, err.Error()).SetRaw(err) } return err }, MIMEApplicationForm: func(i interface{}, ctx Context, filter ...FormDataFilter) error { return NamedStructMap(ctx.Echo(), i, ctx.Request().PostForm().All(), ``, filter...) }, MIMEMultipartForm: func(i interface{}, ctx Context, filter ...FormDataFilter) error { return NamedStructMap(ctx.Echo(), i, ctx.Request().Form().All(), ``, filter...) }, `*`: func(i interface{}, ctx Context, filter ...FormDataFilter) error { return NamedStructMap(ctx.Echo(), i, ctx.Request().Form().All(), ``, filter...) }, } // DefaultHTMLFilter html filter (`form_filter:"html"`) DefaultHTMLFilter = func(v string) (r string) { return v } )
var AsStore = param.AsStore
var (
DefaultCookieOptions = &CookieOptions{
Path: `/`,
}
)
Functions ¶
func CaptureTokens ¶ added in v1.3.5
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 CookieExpires ¶ added in v1.6.0
CookieExpires 设置过期时间 所有浏览器都支持 如果仅仅设置Expires,因为过期时间是固定的,所以不会导致保存Cookie时被续期
func CookieMaxAge ¶ added in v1.6.0
CookieMaxAge 设置有效时长(秒) IE6/7/8不支持 如果同时设置了MaxAge和Expires,则优先使用MaxAge 设置MaxAge则代表每次保存Cookie都会续期,因为MaxAge是基于保存时间来设置的
func CookieSameSite ¶ added in v1.6.0
CookieSameSite 设置SameSite
func CopyCookieOptions ¶ added in v1.6.0
CopyCookieOptions copy cookie options
func DefaultSkipper ¶
DefaultSkipper returns false which processes the middleware.
func Events ¶
func Events() map[string]events.Dispatcher
func FlatStructToForm ¶ added in v1.6.0
func FlatStructToForm(ctx Context, m interface{}, topName string, fieldNameFormatter FieldNameFormatter, formatters ...param.StringerMap)
FlatStructToForm 映射struct到form
func GetOrSet ¶ added in v1.4.2
func GetOrSet(key, value interface{}) (actual interface{}, loaded bool)
func HandlerPath ¶ added in v1.3.7
func HandlerPath(h interface{}) string
HandlerPath returns the handler path
func HandlerTmpl ¶ added in v1.3.7
func NamedStructMap ¶
func NamedStructMap(e *Echo, m interface{}, data map[string][]string, topName string, filters ...FormDataFilter) error
NamedStructMap 自动将map值映射到结构体
func NewCookie ¶
func NewCookie(key, value string, opt *CookieOptions) *http.Cookie
NewCookie 新建cookie对象
func SafeGetFieldByName ¶ added in v1.6.0
func SetFormValue ¶ added in v1.5.0
func SetWorkDir ¶ added in v1.4.3
func SetWorkDir(dir string)
func Split ¶ added in v1.4.3
func Split(key interface{}, sep string, limit ...int) param.StringSlice
func StructToForm ¶ added in v1.1.0
func StructToForm(ctx Context, m interface{}, topName string, fieldNameFormatter FieldNameFormatter, formatters ...param.StringerMap)
StructToForm 映射struct到form
func TranslateStringer ¶ added in v1.6.0
func TranslateStringer(t Translator, args ...interface{}) param.Stringer
Types ¶
type Accepts ¶ added in v1.3.9
func NewAccepts ¶ added in v1.3.9
type AsMiddleware ¶ added in v1.5.0
func (AsMiddleware) Handle ¶ added in v1.5.0
func (m AsMiddleware) Handle(h Handler) Handler
type BaseTransaction ¶ added in v1.3.9
type BaseTransaction struct { Transaction // contains filtered or unexported fields }
func NewTransaction ¶ added in v1.3.9
func NewTransaction(trans Transaction) *BaseTransaction
func (*BaseTransaction) Begin ¶ added in v1.3.9
func (b *BaseTransaction) Begin(ctx context.Context) error
func (*BaseTransaction) Commit ¶ added in v1.3.9
func (b *BaseTransaction) Commit(ctx context.Context) error
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) Handler() Handler //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) NewError(code pkgCode.Code, msg string, args ...interface{}) *Error NewErrorWith(err error, code pkgCode.Code, args ...interface{}) *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.Reader, string, time.Time) error ServeCallbackContent(func(Context) (io.Reader, error), 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) *http.Cookie Cookie() Cookier GetCookie(string) string // SetCookie @param:key,value,maxAge(seconds),path(/),domain,secure,httpOnly,sameSite(lax/strict/default) 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 RequestURI() 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 ¶ added in v1.3.5
type ContextRegister interface {
SetContext(Context)
}
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 // Expires Expires time.Time Path string Domain string Secure bool HttpOnly bool SameSite string // strict / lax }
CookieOptions cookie options
func (*CookieOptions) Clone ¶ added in v1.3.0
func (c *CookieOptions) Clone() *CookieOptions
func (*CookieOptions) SetMaxAge ¶ added in v1.6.0
func (c *CookieOptions) SetMaxAge(maxAge int) *CookieOptions
type Cookier ¶
type Cookier interface { Get(key string) string Add(cookies ...*http.Cookie) Cookier Set(key string, val string, args ...interface{}) Cookier Send() }
Cookier interface
type Data ¶
type Data 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 pkgCode.Code, info interface{}, zone interface{}, data interface{}) GetCode() pkgCode.Code GetInfo() interface{} GetZone() interface{} GetData() interface{} GetURL() string JSONP(callback string, codes ...int) error JSON(codes ...int) error XML(codes ...int) error }
Data 响应数据
type DebugSession ¶ added in v1.3.5
type DebugSession struct { }
func (*DebugSession) AddFlash ¶ added in v1.3.5
func (n *DebugSession) AddFlash(value interface{}, args ...string) Sessioner
func (*DebugSession) AddPreSaveHook ¶ added in v1.6.0
func (n *DebugSession) AddPreSaveHook(_ func(Context) error)
func (*DebugSession) Clear ¶ added in v1.3.5
func (n *DebugSession) Clear() Sessioner
func (*DebugSession) Delete ¶ added in v1.3.5
func (n *DebugSession) Delete(name string) Sessioner
func (*DebugSession) Flashes ¶ added in v1.3.5
func (n *DebugSession) Flashes(args ...string) []interface{}
func (*DebugSession) Get ¶ added in v1.3.5
func (n *DebugSession) Get(name string) interface{}
func (*DebugSession) ID ¶ added in v1.3.5
func (n *DebugSession) ID() string
func (*DebugSession) MustID ¶ added in v1.6.0
func (n *DebugSession) MustID() string
func (*DebugSession) Options ¶ added in v1.3.5
func (n *DebugSession) Options(options SessionOptions) Sessioner
func (*DebugSession) Save ¶ added in v1.3.5
func (n *DebugSession) Save() error
func (*DebugSession) Set ¶ added in v1.3.5
func (n *DebugSession) Set(name string, value interface{}) Sessioner
func (*DebugSession) SetID ¶ added in v1.3.5
func (n *DebugSession) SetID(id string) Sessioner
func (*DebugSession) SetPreSaveHook ¶ added in v1.6.0
func (n *DebugSession) SetPreSaveHook(_ ...func(Context) error)
type DebugTransaction ¶ added in v1.5.0
type DebugTransaction struct { }
func (*DebugTransaction) Begin ¶ added in v1.5.0
func (b *DebugTransaction) Begin(ctx context.Context) error
func (*DebugTransaction) Commit ¶ added in v1.5.0
func (b *DebugTransaction) Commit(ctx context.Context) error
type Echo ¶
type Echo struct { FuncMap map[string]interface{} RouteDebug bool MiddlewareDebug bool JSONPVarName string Validator Validator FormSliceMaxIndex int // contains filtered or unexported fields }
func NewWithContext ¶
func (*Echo) Add ¶ added in v1.6.0
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 ¶ added in v1.3.0
func (*Echo) AddFormatRenderer ¶ added in v1.3.7
func (*Echo) AddHandlerWrapper ¶ added in v1.1.0
func (*Echo) AddMiddlewareWrapper ¶ added in v1.1.0
func (e *Echo) AddMiddlewareWrapper(funcs ...func(interface{}) Middleware)
func (*Echo) AppendRouter ¶
AppendRouter append router
func (*Echo) Clear ¶ added in v1.3.0
func (e *Echo) Clear(middleware ...interface{})
Clear middleware
func (*Echo) ClearPre ¶ added in v1.6.0
func (e *Echo) ClearPre(middleware ...interface{})
ClearPre Clear premiddleware
func (*Echo) DefaultHTTPErrorHandler ¶
DefaultHTTPErrorHandler invokes the default HTTP error handler.
func (*Echo) HTTPErrorHandler ¶ added in v1.3.0
func (e *Echo) HTTPErrorHandler() HTTPErrorHandler
HTTPErrorHandler returns the HTTPErrorHandler
func (*Echo) Host ¶ added in v1.6.0
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 ¶
func (e *Echo) MetaHandler(m H, handler interface{}, requests ...RequestValidator) Handler
MetaHandler Add meta information about endpoint
func (*Echo) NamedRoutes ¶
NamedRoutes returns the registered handler name.
func (*Echo) NewContext ¶ added in v1.5.0
func (*Echo) ParseHeaderAccept ¶ added in v1.3.9
func (*Echo) Pre ¶
func (e *Echo) Pre(middleware ...interface{})
Pre adds handler to the middleware chain.
func (*Echo) RebuildRouter ¶
RebuildRouter rebuild router
func (*Echo) RemoveFormatRenderer ¶ added in v1.3.7
func (*Echo) SetAcceptFormats ¶ added in v1.3.0
func (*Echo) SetFormSliceMaxIndex ¶ added in v1.6.0
func (*Echo) SetFormatRenderers ¶ added in v1.3.7
func (*Echo) SetHTTPErrorHandler ¶
func (e *Echo) SetHTTPErrorHandler(h HTTPErrorHandler)
SetHTTPErrorHandler registers a custom Echo.HTTPErrorHandler.
func (*Echo) SetHandlerWrapper ¶ added in v1.1.0
func (*Echo) SetMiddlewareWrapper ¶ added in v1.1.0
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) SetValidator ¶ added in v1.6.0
func (*Echo) Static ¶ added in v1.3.0
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 Error ¶ added in v1.6.0
type Error struct { Code pkgCode.Code Message string Zone string Extra H // contains filtered or unexported fields }
func NewErrorWith ¶ added in v1.6.0
type FieldNameFormatter ¶ added in v1.1.0
FieldNameFormatter 结构体字段值映射到表单时,结构体字段名称格式化处理
type FormDataFilter ¶ added in v1.1.0
FormDataFilter 将map映射到结构体时,对名称和值的过滤处理,如果返回的名称为空,则跳过本字段
func ExcludeFieldName ¶ added in v1.5.0
func ExcludeFieldName(fieldNames ...string) FormDataFilter
ExcludeFieldName 排除字段
func FormatFieldValue ¶ added in v1.5.0
func FormatFieldValue(formatters map[string]FormDataFilter) FormDataFilter
FormatFieldValue 格式化字段值
func IncludeFieldName ¶ added in v1.5.0
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 ¶ added in v1.3.5
func (g *Group) MetaHandler(m H, handler interface{}, requests ...RequestValidator) Handler
MetaHandler Add meta information about endpoint
func (*Group) Pre ¶
func (g *Group) Pre(middleware ...interface{})
Pre adds handler to the middleware chain.
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 Host ¶ added in v1.6.0
type Host struct { Router *Router // contains filtered or unexported fields }
type ICore ¶ added in v1.1.0
type ICore interface { RouteRegister URLBuilder RendererRegister Prefixer }
type KV ¶ added in v1.1.1
type KV struct { K string V string H H `json:",omitempty" xml:",omitempty"` X interface{} `json:",omitempty" xml:",omitempty"` // contains filtered or unexported fields }
KV 键值对
type KVData ¶ added in v1.1.1
type KVData struct {
// contains filtered or unexported fields
}
KVData 键值对数据(保持顺序)
type Mapx ¶ added in v1.1.1
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 ¶ added in v1.4.0
type MetaHandler ¶ added in v1.3.0
type MetaHandler struct { Handler // contains filtered or unexported fields }
func (*MetaHandler) Handle ¶ added in v1.6.0
func (m *MetaHandler) Handle(c Context) error
func (*MetaHandler) Meta ¶ added in v1.3.0
func (m *MetaHandler) Meta() H
func (*MetaHandler) Name ¶ added in v1.3.5
func (m *MetaHandler) Name() string
type MetaValidator ¶ added in v1.6.0
type MetaValidator interface { Validate(Context) error Filters(Context) []FormDataFilter }
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 ¶ added in v1.1.0
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) AddPreSaveHook ¶ added in v1.6.0
func (n *NopSession) AddPreSaveHook(_ func(Context) error)
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 ¶ added in v1.3.0
func (n *NopSession) ID() string
func (*NopSession) MustID ¶ added in v1.6.0
func (n *NopSession) MustID() 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 ¶ added in v1.3.0
func (n *NopSession) SetID(id string) Sessioner
func (*NopSession) SetPreSaveHook ¶ added in v1.6.0
func (n *NopSession) SetPreSaveHook(_ ...func(Context) error)
type NopTranslate ¶
type NopTranslate struct {
// contains filtered or unexported fields
}
func (*NopTranslate) E ¶ added in v1.4.3
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 ¶ added in v1.2.0
type NopValidation struct { }
func (*NopValidation) Validate ¶ added in v1.2.0
func (v *NopValidation) Validate(_ interface{}, _ ...string) ValidateResult
type PanicError ¶ added in v1.3.0
type PanicError struct { Raw interface{} Traces []*Trace Snippets []*SnippetGroup // contains filtered or unexported fields }
func NewPanicError ¶ added in v1.3.0
func NewPanicError(recovered interface{}, err error, debugAndDisableStackAll ...bool) *PanicError
func (*PanicError) AddTrace ¶ added in v1.3.0
func (p *PanicError) AddTrace(trace *Trace) *PanicError
func (*PanicError) Debug ¶ added in v1.3.0
func (p *PanicError) Debug() bool
func (*PanicError) Error ¶ added in v1.3.0
func (p *PanicError) Error() string
func (*PanicError) ExtractSnippets ¶ added in v1.3.0
func (p *PanicError) ExtractSnippets(file string, curLineNum int, index int) error
func (*PanicError) HTML ¶ added in v1.3.0
func (p *PanicError) HTML() template.HTML
func (*PanicError) JSONString ¶ added in v1.3.0
func (p *PanicError) JSONString() string
func (*PanicError) Parse ¶ added in v1.4.3
func (p *PanicError) Parse(stackSizes ...int) *PanicError
func (*PanicError) SetDebug ¶ added in v1.3.0
func (p *PanicError) SetDebug(on bool) *PanicError
func (*PanicError) SetError ¶ added in v1.3.0
func (p *PanicError) SetError(err error) *PanicError
func (*PanicError) SetErrorString ¶ added in v1.3.0
func (p *PanicError) SetErrorString(errStr string) *PanicError
func (*PanicError) String ¶ added in v1.3.0
func (p *PanicError) String() string
type RawData ¶ added in v1.3.0
type RawData struct { Code pkgCode.Code 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 }
func (*RawData) SetContext ¶ added in v1.3.0
SetContext 设置Context
type RendererRegister ¶ added in v1.4.3
type RendererRegister interface {
SetRenderer(Renderer)
}
type RequestValidator ¶ added in v1.6.0
type RequestValidator func() MetaValidator
type Route ¶
type Route struct { Host string Method string Path string Handler Handler `json:"-" xml:"-"` Name string Format string Params []string //param names Prefix string Meta H // contains filtered or unexported fields }
type RouteRegister ¶ added in v1.1.0
type RouteRegister interface { MiddlewareRegister 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 ¶ added in v1.4.0
func NewSessionOptions(engine string, name string, args ...*CookieOptions) *SessionOptions
func (*SessionOptions) Clone ¶ added in v1.3.0
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 MustID() 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 AddPreSaveHook(func(Context) error) SetPreSaveHook(...func(Context) 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 ¶ added in v1.3.0
func (*SnippetGroup) String ¶ added in v1.3.0
func (sg *SnippetGroup) String() string
func (*SnippetGroup) TableRow ¶ added in v1.3.0
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 ¶ added in v1.3.9
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 = NewTransaction(nil) 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 ¶ added in v1.1.0
type URLBuilder interface {
URL(interface{}, ...interface{}) string
}
type ValidateResult ¶ added in v1.3.0
type ValidateResult interface { Ok() bool Error() error Field() string Raw() interface{} //setter SetError(error) ValidateResult SetField(string) ValidateResult SetRaw(interface{}) ValidateResult }
func NewValidateResult ¶ added in v1.3.0
func NewValidateResult() ValidateResult
type Validation ¶ added in v1.2.0
type Validation struct {
// contains filtered or unexported fields
}
func (*Validation) Validate ¶ added in v1.2.0
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 ¶ added in v1.2.0
func NewValidation() Validator
type ValidatorResult ¶ added in v1.3.0
type ValidatorResult struct {
// contains filtered or unexported fields
}
func (*ValidatorResult) Error ¶ added in v1.3.0
func (v *ValidatorResult) Error() error
func (*ValidatorResult) Field ¶ added in v1.3.0
func (v *ValidatorResult) Field() string
func (*ValidatorResult) Ok ¶ added in v1.3.0
func (v *ValidatorResult) Ok() bool
func (*ValidatorResult) Raw ¶ added in v1.3.0
func (v *ValidatorResult) Raw() interface{}
func (*ValidatorResult) SetError ¶ added in v1.3.0
func (v *ValidatorResult) SetError(err error) ValidateResult
func (*ValidatorResult) SetField ¶ added in v1.3.0
func (v *ValidatorResult) SetField(field string) ValidateResult
func (*ValidatorResult) SetRaw ¶ added in v1.3.0
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
- data_kv.go
- echo.go
- echo_host.go
- error.go
- event.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
- variable_default.go
- wrapper.go
Directories ¶
Path | Synopsis |
---|---|
encoding
|
|
handler
|
|
mvc/static/minify
Package cssmin minifies CSS.
|
Package cssmin minifies CSS. |
websocket/example
Module
|
|
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> |