Documentation ¶
Index ¶
- Constants
- Variables
- func DELETE(handlers ...HandleFunc) methodOption
- func EWEBLogger(log *elog.Log)
- func GET(handlers ...HandleFunc) methodOption
- func HEAD(handlers ...HandleFunc) methodOption
- func Handle(method string, handlers ...HandleFunc) methodOption
- func MethodColor(method string) string
- func Mode() string
- func OPTIONS(handlers ...HandleFunc) methodOption
- func PATCH(handlers ...HandleFunc) methodOption
- func POST(handlers ...HandleFunc) methodOption
- func PUT(handlers ...HandleFunc) methodOption
- func ResetColor() string
- func SetMode(value string)
- func SkipPath(paths ...string)
- func StatusCodeColor(code int) string
- func Use(handlers ...HandleFunc) methodOption
- type Accounts
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortWithStatus(code int)
- func (c *Context) AddHeader(key, value string)
- func (c *Context) ContentType() string
- func (c *Context) Cookie(name string) (string, error)
- func (c *Context) Copy() *Context
- func (c *Context) Data(code int, data []byte)
- func (c *Context) DefaultPostForm(key, defaultValue string) string
- func (c *Context) DefaultQuery(key, defaultValue string) string
- func (c *Context) DelHeader(key string)
- func (c *Context) Fail(code int, errStr string)
- func (c *Context) File(path string)
- func (c *Context) FileAttachment(path, name string)
- func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Context) Forward(location string)
- func (c *Context) Get(key string) (value interface{}, ok bool)
- func (c *Context) GetB(key string) (s bool)
- func (c *Context) GetDuration(key string) (d time.Duration)
- func (c *Context) GetF64(key string) (f float64)
- func (c *Context) GetI(key string) (i int)
- func (c *Context) GetI64(key string) (i int64)
- func (c *Context) GetMSSliceS(key string) (m map[string][]string)
- func (c *Context) GetMapI(key string) (s map[int]interface{})
- func (c *Context) GetMapS(key string) (m map[string]interface{})
- func (c *Context) GetMapSS(key string) (m map[string]string)
- func (c *Context) GetPostForm(key string) (string, bool)
- func (c *Context) GetPostFormArray(key string) ([]string, bool)
- func (c *Context) GetQuery(key string) (string, bool)
- func (c *Context) GetQueryArray(key string) ([]string, bool)
- func (c *Context) GetS(key string) (s string)
- func (c *Context) GetSliceS(key string) (s []string)
- func (c *Context) GetTime(key string) (t time.Time)
- func (c *Context) GetU(key string) (u uint)
- func (c *Context) GetU64(key string) (u uint64)
- func (c *Context) HTML(code int, name string, data interface{})
- func (c *Context) Header(key string) string
- func (c *Context) HeaderKeys() (keys []string)
- func (c *Context) Headers() http.Header
- func (c *Context) IsAbort() bool
- func (c *Context) JSON(code int, obj interface{})
- func (c *Context) MultipartForm() (*multipart.Form, error)
- func (c *Context) MustGet(key string) interface{}
- func (c *Context) Next()
- func (c *Context) Param(key string) string
- func (c *Context) PostForm(key string) string
- func (c *Context) PostFormArray(key string) []string
- func (c *Context) Query(key string) string
- func (c *Context) QueryArray(key string) []string
- func (c *Context) Redirect(code int, location string)
- func (c *Context) Render(code int, r render.Render)
- func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
- func (c *Context) Set(key string, value interface{})
- func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) Status(code int)
- func (c *Context) String(code int, format string, values ...interface{})
- func (c *Context) Success(msg string)
- type Engine
- func (engine *Engine) HandleContext(c *Context)
- func (engine *Engine) LoadHTMLGlob(pattern string)
- func (engine *Engine) NoMethod(handlers ...HandleFunc)
- func (engine *Engine) NoRoute(handlers ...HandleFunc)
- func (engine *Engine) Run(addr ...string) (err error)
- func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (engine *Engine) SetFuncMap(funcMap template.FuncMap)
- func (engine *Engine) Use(middleware ...HandleFunc) IRoutes
- type H
- type HandleChain
- type HandleFunc
- type IRouter
- type IRoutes
- type Param
- type Params
- type ResponseWriter
- type RouterGroup
- func (g *RouterGroup) DELETE(path string, handlers ...HandleFunc) IRoutes
- func (g *RouterGroup) GET(path string, handlers ...HandleFunc) IRoutes
- func (g *RouterGroup) Group(prefix string, handlers ...HandleFunc) *RouterGroup
- func (g *RouterGroup) HEAD(path string, handlers ...HandleFunc) IRoutes
- func (g *RouterGroup) Handle(method, relPath string, handlers ...HandleFunc) IRoutes
- func (g *RouterGroup) OPTIONS(path string, handlers ...HandleFunc) IRoutes
- func (g *RouterGroup) PATCH(path string, handlers ...HandleFunc) IRoutes
- func (g *RouterGroup) POST(path string, handlers ...HandleFunc) IRoutes
- func (g *RouterGroup) PUT(path string, handlers ...HandleFunc) IRoutes
- func (g *RouterGroup) Route(path string, options ...methodOption) IRoutes
- func (group *RouterGroup) Static(relPath string, root string)
- func (group *RouterGroup) Use(middleware ...HandleFunc) IRoutes
Constants ¶
const ( MIMEJSON = "application/json; charset=utf-8" MIMEPlain = "text/plain; charset=utf-8" MIMEHTML = "text/html; charset=utf-8" )
const ( DevMode = "Dev" ProdMode = "Prod" TestMode = "Test" )
const AuthUserKey = "user"
AuthUserKey is the cookie name for user credential in basic auth.
const EnvMode = "EWEB_MODE"
Variables ¶
var DevPrintRouteFunc func(httpMethod, absPath string, handlerName string, num int)
Functions ¶
func DELETE ¶
func DELETE(handlers ...HandleFunc) methodOption
func EWEBLogger ¶
func GET ¶
func GET(handlers ...HandleFunc) methodOption
func HEAD ¶
func HEAD(handlers ...HandleFunc) methodOption
func Handle ¶
func Handle(method string, handlers ...HandleFunc) methodOption
func MethodColor ¶
func OPTIONS ¶
func OPTIONS(handlers ...HandleFunc) methodOption
func PATCH ¶
func PATCH(handlers ...HandleFunc) methodOption
func POST ¶
func POST(handlers ...HandleFunc) methodOption
func PUT ¶
func PUT(handlers ...HandleFunc) methodOption
func ResetColor ¶
func ResetColor() string
func StatusCodeColor ¶
func Use ¶
func Use(handlers ...HandleFunc) methodOption
Types ¶
type Context ¶
type Context struct { Writer ResponseWriter Req *http.Request // request info Path string Params Params Keys map[string]interface{} // contains filtered or unexported fields }
func (*Context) AbortWithStatus ¶
func (*Context) ContentType ¶
func (*Context) DefaultPostForm ¶
func (*Context) DefaultQuery ¶
func (*Context) FileAttachment ¶
func (*Context) HeaderKeys ¶
func (*Context) MultipartForm ¶
multipart
func (*Context) PostFormArray ¶
func (*Context) QueryArray ¶
func (*Context) SaveUploadedFile ¶
func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
type Engine ¶
type Engine struct { *RouterGroup // 默认为 false,如果为 true,则使用 url.RawPath 查找参数 UseRawPath bool // 如果为 true,则 path 会被解码。 // 如果 UseRawPath 为 false,则 UnescapePathValues 为 true,url.Path 会被拿去查找参数 // 如果 UseRawPath 为 true,则 UnescapePathValues 为 false,url.RawPath 会被拿去查找参数 UnescapePathValues bool // 如果当前路由无法匹配,但存在带有(不带)结尾斜杠的路径的 handlerFunc,则启用自动重定向。 // 例如,如果请求了/foo/但路由只存在于/foo中,客户端将被重定向到/foo。 // GET请求的状态码将被修改为 301,所有其他请求方法的状态码将被修改为 307。 RedirectTrailingSlash bool RemoveExtraSlash bool MaxMultipartMemory int64 HandleMethodNotAllowed bool // contains filtered or unexported fields }
func New ¶
func New() *Engine
New 返回一个引擎对象,引擎对象中管理着一片`方法树林`和一棵`分组树` 方法树林最多有9棵方法树,对应了 RESTFul API 的9种方法 分组树仅有一棵,以引擎为根结点。 New returns an Engine object, which manages a `method forest` and a `grouping tree`. The method forest has a maximum of 9 method trees, corresponding to the 9 RESTFul API methods, and only one grouping tree, with the engine as the root node.
func (*Engine) HandleContext ¶
func (*Engine) LoadHTMLGlob ¶
func (*Engine) NoMethod ¶
func (engine *Engine) NoMethod(handlers ...HandleFunc)
func (*Engine) Run ¶
Run 用于启动http服务,需要接收一个端口号 如果没有传入端口号,默认使用8080端口 Run is used to start the HTTP service and needs a port number. The port 8080 is used by default if no port number is passed in.
func (*Engine) ServeHTTP ¶
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*Engine) Use ¶
func (engine *Engine) Use(middleware ...HandleFunc) IRoutes
type HandleChain ¶
type HandleChain []HandleFunc
HandleChain defines a Array of HandlerFunc.
func (HandleChain) Last ¶
func (c HandleChain) Last() HandleFunc
Last return the last handler in the handler chain.
type HandleFunc ¶
type HandleFunc func(*Context)
HandleFunc defines the handler used by middlerware or route.
func BasicAuth ¶
func BasicAuth(account Accounts) HandleFunc
func BasicAuthForRealm ¶
func BasicAuthForRealm(account Accounts, realm string) HandleFunc
func CORS ¶
func CORS(origin ...string) HandleFunc
CORS returns a middleware that sets the cross-domain response header.
func Logger ¶
func Logger() HandleFunc
func LoggerWithWriter ¶
func LoggerWithWriter(w io.Writer) HandleFunc
func Recovery ¶
func Recovery() HandleFunc
type IRouter ¶
type IRouter interface { IRoutes Group(string, ...HandleFunc) *RouterGroup }
type IRoutes ¶
type IRoutes interface { Use(...HandleFunc) IRoutes Handle(string, string, ...HandleFunc) IRoutes GET(string, ...HandleFunc) IRoutes POST(string, ...HandleFunc) IRoutes PUT(string, ...HandleFunc) IRoutes DELETE(string, ...HandleFunc) IRoutes OPTIONS(string, ...HandleFunc) IRoutes HEAD(string, ...HandleFunc) IRoutes PATCH(string, ...HandleFunc) IRoutes }
type ResponseWriter ¶
type RouterGroup ¶
type RouterGroup struct { Middleware HandleChain // 附属于该分组的中间件 // contains filtered or unexported fields }
func (*RouterGroup) DELETE ¶
func (g *RouterGroup) DELETE(path string, handlers ...HandleFunc) IRoutes
func (*RouterGroup) GET ¶
func (g *RouterGroup) GET(path string, handlers ...HandleFunc) IRoutes
func (*RouterGroup) Group ¶
func (g *RouterGroup) Group(prefix string, handlers ...HandleFunc) *RouterGroup
func (*RouterGroup) HEAD ¶
func (g *RouterGroup) HEAD(path string, handlers ...HandleFunc) IRoutes
func (*RouterGroup) Handle ¶
func (g *RouterGroup) Handle(method, relPath string, handlers ...HandleFunc) IRoutes
func (*RouterGroup) OPTIONS ¶
func (g *RouterGroup) OPTIONS(path string, handlers ...HandleFunc) IRoutes
func (*RouterGroup) PATCH ¶
func (g *RouterGroup) PATCH(path string, handlers ...HandleFunc) IRoutes
func (*RouterGroup) POST ¶
func (g *RouterGroup) POST(path string, handlers ...HandleFunc) IRoutes
func (*RouterGroup) PUT ¶
func (g *RouterGroup) PUT(path string, handlers ...HandleFunc) IRoutes
func (*RouterGroup) Route ¶
func (g *RouterGroup) Route(path string, options ...methodOption) IRoutes
Route is a options design pattern style interface. It provides a shortcut to many handlers which is same path but different request method.
example:
g.Route("/login", Use(Logger), GET(indexHandler), POST(loginHandler), )
equals:
g.Use(Logger) g.GET("/login", indexHandler) g.POST("/login", loginHandler)
Attention! if you use the Method Use(), it will register the middlerware on group instead of route, just like the example, that will act on all the group's routes. You can write like `GET(indexHandler, Logger)` when you wanna act on special route.
func (*RouterGroup) Static ¶
func (group *RouterGroup) Static(relPath string, root string)
serve static files
func (*RouterGroup) Use ¶
func (group *RouterGroup) Use(middleware ...HandleFunc) IRoutes
===================== === IRoutes 方法集 === =====================