Documentation
¶
Index ¶
- Constants
- Variables
- func Dfs(n *Node)
- type Context
- func (ctx *Context) BaseContext() context.Context
- func (ctx *Context) BindJson(obj interface{}) error
- func (ctx *Context) Deadline() (deadline time.Time, ok bool)
- func (ctx *Context) Done() <-chan struct{}
- func (ctx *Context) Err() error
- func (ctx *Context) FormAll() map[string][]string
- func (ctx *Context) FormArray(key string, def []string) []string
- func (ctx *Context) FormInt(key string, def int) int
- func (ctx *Context) FormString(key string, def string) string
- func (ctx *Context) GetRequest() *http.Request
- func (ctx *Context) GetResponse() http.ResponseWriter
- func (ctx *Context) HTML(status int, obj interface{}, template string) error
- func (ctx *Context) HasTimeout() bool
- func (ctx *Context) Json(status int, obj interface{}) error
- func (ctx *Context) Next() error
- func (ctx *Context) QueryAll() map[string][]string
- func (ctx *Context) QueryArray(key string, def []string) []string
- func (ctx *Context) QueryInt(key string, def int) int
- func (ctx *Context) QueryString(key string, def string) string
- func (ctx *Context) SetHasTimeout()
- func (ctx *Context) Text(status int, obj string) error
- func (ctx *Context) Value(key interface{}) interface{}
- type ControllerHandler
- type Engin
- func (engin *Engin) Delete(url string, handler ControllerHandler)
- func (engin *Engin) FindHandlerByRequest(request *http.Request) []ControllerHandler
- func (engin *Engin) Get(url string, handler ControllerHandler)
- func (engin *Engin) Group(prefix string) IGroup
- func (engin *Engin) Post(url string, handler ControllerHandler)
- func (engin *Engin) Put(url string, handler ControllerHandler)
- func (engin *Engin) Run(addr string) error
- func (engin *Engin) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (engin *Engin) Use(middlewares ...ControllerHandler)
- type Group
- type IGroup
- type IRouter
- type Node
- type RouterInformation
- type SimpleRouter
- type StandardRouter
- type Tree
Constants ¶
View Source
const ( GET = "GET" POST = "POST" PUT = "PUT" DELETE = "DELETE" )
Variables ¶
View Source
var (
DefaultMiddlewares []ControllerHandler = []ControllerHandler{Recover(), TimeoutMonitor(100 * time.Second)}
)
Functions ¶
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
自定义Context 请求控制器 关于middleWares自己的一点感悟,相当于java的aop编程
func NewContext ¶
func NewContext(r *http.Request, w http.ResponseWriter) *Context
func (*Context) BaseContext ¶
func (*Context) GetRequest ¶
最基本的方法, 将封装的东西通过某种方法暴漏给外部使用,也叫base base
func (*Context) GetResponse ¶
func (ctx *Context) GetResponse() http.ResponseWriter
func (*Context) HasTimeout ¶
func (*Context) SetHasTimeout ¶
func (ctx *Context) SetHasTimeout()
type ControllerHandler ¶
自定义控制器
func Recover ¶
func Recover() ControllerHandler
func TimeoutMonitor ¶
func TimeoutMonitor(d time.Duration) ControllerHandler
type Engin ¶
type Engin struct {
// contains filtered or unexported fields
}
func NewDefaultEngin ¶
func NewDefaultEngin() *Engin
func NewSimpleEngin ¶
func NewSimpleEngin() *Engin
func (*Engin) Delete ¶
func (engin *Engin) Delete(url string, handler ControllerHandler)
func (*Engin) FindHandlerByRequest ¶
func (engin *Engin) FindHandlerByRequest(request *http.Request) []ControllerHandler
func (*Engin) Get ¶
func (engin *Engin) Get(url string, handler ControllerHandler)
func (*Engin) Post ¶
func (engin *Engin) Post(url string, handler ControllerHandler)
func (*Engin) Put ¶
func (engin *Engin) Put(url string, handler ControllerHandler)
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
实现group接口
func (*Group) Delete ¶
func (g *Group) Delete(uri string, handler ControllerHandler)
func (*Group) Get ¶
func (g *Group) Get(uri string, handler ControllerHandler)
func (*Group) Post ¶
func (g *Group) Post(uri string, handler ControllerHandler)
func (*Group) Put ¶
func (g *Group) Put(uri string, handler ControllerHandler)
type IGroup ¶
type IGroup interface { Get(string, ControllerHandler) Post(string, ControllerHandler) Put(string, ControllerHandler) Delete(string, ControllerHandler) }
定义group接口 谈一些group的感想,一句话,group间接的去操作core.router目的就是注册路由,是一个非常巧妙的设计风格
type IRouter ¶
type IRouter interface { RegisterRoute(information RouterInformation, middlewares []ControllerHandler) error FindHandlerByRouterInformation(information RouterInformation) []ControllerHandler }
主要是存取方法
type RouterInformation ¶
定义一个路由接口,进一步实现解耦 面向接口设计而不是面向实现设计
type SimpleRouter ¶
type SimpleRouter struct {
Url2Handler map[string]map[string][]ControllerHandler
}
func (*SimpleRouter) FindHandlerByRouterInformation ¶
func (r *SimpleRouter) FindHandlerByRouterInformation(information RouterInformation) []ControllerHandler
func (*SimpleRouter) RegisterRoute ¶
func (r *SimpleRouter) RegisterRoute(information RouterInformation, middlewares []ControllerHandler) error
type StandardRouter ¶
func NewStandardRouter ¶
func NewStandardRouter() *StandardRouter
func (*StandardRouter) FindHandlerByRouterInformation ¶
func (s *StandardRouter) FindHandlerByRouterInformation(information RouterInformation) []ControllerHandler
func (*StandardRouter) RegisterRoute ¶
func (s *StandardRouter) RegisterRoute(information RouterInformation, handlers []ControllerHandler) error
写的有问题, correct
Click to show internal directories.
Click to hide internal directories.