Documentation
¶
Index ¶
- type Container
- type Context
- func (ctx *Context) BaseContext() context.Context
- func (ctx *Context) BindJson(obj interface{}) error
- func (ctx *Context) BindXml(obj interface{}) error
- func (ctx *Context) Done() <-chan struct{}
- func (ctx *Context) Form(key string) interface{}
- func (ctx *Context) FormAll() map[string][]string
- func (ctx *Context) FormBool(key string, def bool) (bool, bool)
- func (ctx *Context) FormFile(key string) (*multipart.FileHeader, error)
- func (ctx *Context) FormFloat32(key string, def float32) (float32, bool)
- func (ctx *Context) FormFloat64(key string, def float64) (float64, bool)
- func (ctx *Context) FormInt(key string, def int) (int, bool)
- func (ctx *Context) FormInt64(key string, def int64) (int64, bool)
- func (ctx *Context) FormString(key string, def string) (string, bool)
- func (ctx *Context) FormStringSlice(key string, def []string) ([]string, bool)
- func (ctx *Context) GetRequest() *http.Request
- func (ctx *Context) GetResponse() http.ResponseWriter
- func (ctx *Context) Html(file string, obj interface{}) IResponse
- func (ctx *Context) Json(obj interface{}) IResponse
- func (ctx *Context) Jsonp(obj interface{}) IResponse
- func (ctx *Context) Next() error
- func (ctx *Context) Param(key string) interface{}
- func (ctx *Context) ParamBool(key string, def bool) (bool, bool)
- func (ctx *Context) ParamFloat32(key string, def float32) (float32, bool)
- func (ctx *Context) ParamFloat64(key string, def float64) (float64, bool)
- func (ctx *Context) ParamInt(key string, def int) (int, bool)
- func (ctx *Context) ParamInt64(key string, def int64) (int64, bool)
- func (ctx *Context) ParamString(key string, def string) (string, bool)
- func (ctx *Context) Query(key string) interface{}
- func (ctx *Context) QueryAll() map[string][]string
- func (ctx *Context) QueryBool(key string, def bool) (bool, bool)
- func (ctx *Context) QueryFloat32(key string, def float32) (float32, bool)
- func (ctx *Context) QueryFloat64(key string, def float64) (float64, bool)
- func (ctx *Context) QueryInt(key string, def int) (int, bool)
- func (ctx *Context) QueryInt64(key string, def int64) (int64, bool)
- func (ctx *Context) QueryString(key string, def string) (string, bool)
- func (ctx *Context) QueryStringSlice(key string, def []string) ([]string, bool)
- func (ctx *Context) Redirect(path string) IResponse
- func (ctx *Context) SetCookie(key string, val string, maxAge int, path string, domain string, secure bool, ...) IResponse
- func (ctx *Context) SetHandlers(handlers []ControllerHandler)
- func (ctx *Context) SetHasTimeout()
- func (ctx *Context) SetHeader(key string, val string) IResponse
- func (ctx *Context) SetOkStatus() IResponse
- func (ctx *Context) SetParams(params map[string]string)
- func (ctx *Context) SetStatus(code int) IResponse
- func (ctx *Context) Text(format string, values ...interface{}) IResponse
- func (ctx *Context) WriterMux() *sync.Mutex
- func (ctx *Context) Xml(obj interface{}) IResponse
- type ControllerHandler
- type Core
- func (c *Core) Delete(url string, handlers ...ControllerHandler)
- func (c *Core) FindRouteByRequest(request *http.Request) []ControllerHandler
- func (c *Core) FindRouteNodeByRequest(request *http.Request) *node
- func (c *Core) Get(url string, handlers ...ControllerHandler)
- func (c *Core) Group(prefix string) IGroup
- func (c *Core) Post(url string, handlers ...ControllerHandler)
- func (c *Core) Put(url string, handlers ...ControllerHandler)
- func (c *Core) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (c *Core) Use(middlewares ...ControllerHandler)
- type Group
- func (g *Group) Delete(uri string, handlers ...ControllerHandler)
- func (g *Group) Get(uri string, handlers ...ControllerHandler)
- func (g *Group) Group(prefix string) IGroup
- func (g *Group) Post(uri string, handlers ...ControllerHandler)
- func (g *Group) Put(uri string, handlers ...ControllerHandler)
- func (g *Group) Use(middlewares ...ControllerHandler)
- type IGroup
- type IRequest
- type IResponse
- type LadeContainer
- func (lade *LadeContainer) Bind(provider ServiceProvider) error
- func (lade *LadeContainer) Make(key string) (interface{}, error)
- func (lade *LadeContainer) MakeNew(key string, params []interface{}) (interface{}, error)
- func (lade *LadeContainer) MustMake(key string) interface{}
- func (lade *LadeContainer) NameList() []string
- func (lade *LadeContainer) PrintProviders() []string
- type NewInstance
- type ServiceProvider
- type Tree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container interface { // Bind 绑定一个服务提供者,如果关键字凭证已经存在,会进行替换操作,相同凭证对应提供者替换为新的提供者,返回 error Bind(provider ServiceProvider) error // 判断关键字凭证是否已经绑定提供者 IsBind(key string) bool // 根据关键字凭证获取一个服务 Make(key string) (interface{}, error) // MustMake 根据关键字凭证获取一个服务,如果这个关键字凭证未绑定服务提供者,那么会 panic。 // 所以在使用这个接口的时候请保证服务容器已经为这个关键字凭证绑定了服务提供者 MustMake(key string) interface{} // MakeNew 根据关键字凭证获取一个服务,只是这个服务并不是单例模式的 // 它是根据服务提供者注册的启动函数和传递的 params 参数实例化出来的 // 这个函数在需要为不同参数启动不同实例的时候非常有用 MakeNew(key string, params []interface{}) (interface{}, error) }
Container 是一个服务容器,提供绑定服务和获取服务的功能
type Context ¶
type Context struct { // Container LadeContainer // contains filtered or unexported fields }
func NewContext ¶
func NewContext(request *http.Request, response http.ResponseWriter) *Context
func (*Context) BaseContext ¶
func (*Context) FormFile ¶
func (ctx *Context) FormFile(key string) (*multipart.FileHeader, error)
使用request.MultipartForm
func (*Context) FormFloat32 ¶
func (*Context) FormFloat64 ¶
func (*Context) FormStringSlice ¶
func (*Context) GetRequest ¶
func (*Context) GetResponse ¶
func (ctx *Context) GetResponse() http.ResponseWriter
func (*Context) ParamFloat32 ¶
func (*Context) ParamFloat64 ¶
func (*Context) ParamString ¶
func (*Context) QueryFloat32 ¶
func (*Context) QueryFloat64 ¶
func (*Context) QueryString ¶
func (*Context) QueryStringSlice ¶
func (*Context) SetCookie ¶
func (ctx *Context) SetCookie(key string, val string, maxAge int, path string, domain string, secure bool, httpOnly bool) IResponse
Cookie
func (*Context) SetHandlers ¶
func (ctx *Context) SetHandlers(handlers []ControllerHandler)
设置handlers
func (*Context) SetHasTimeout ¶
func (ctx *Context) SetHasTimeout()
type ControllerHandler ¶
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
func (*Core) Delete ¶
func (c *Core) Delete(url string, handlers ...ControllerHandler)
func (*Core) FindRouteByRequest ¶
func (c *Core) FindRouteByRequest(request *http.Request) []ControllerHandler
func (*Core) FindRouteNodeByRequest ¶
寻找匹配最终节点
func (*Core) Post ¶
func (c *Core) Post(url string, handlers ...ControllerHandler)
func (*Core) Put ¶
func (c *Core) Put(url string, handlers ...ControllerHandler)
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func (*Group) Delete ¶
func (g *Group) Delete(uri string, handlers ...ControllerHandler)
func (*Group) Get ¶
func (g *Group) Get(uri string, handlers ...ControllerHandler)
func (*Group) Post ¶
func (g *Group) Post(uri string, handlers ...ControllerHandler)
func (*Group) Put ¶
func (g *Group) Put(uri string, handlers ...ControllerHandler)
type IGroup ¶
type IGroup interface { Get(string, ...ControllerHandler) Post(string, ...ControllerHandler) Put(string, ...ControllerHandler) Delete(string, ...ControllerHandler) Use(...ControllerHandler) }
type IRequest ¶
type IRequest interface { // 解析请求地址url中带的参数 // 形如: foo.com?a=1&b=bar&c []=bar QueryInt(key string, def int) (int, bool) QueryInt64(key string, def int64) (int64, bool) QueryFloat64(key string, def float64) (float64, bool) QueryFloat32(key string, def float32) (float32, bool) QueryBool(key string, def bool) (bool, bool) QueryString(key string, def string) (string, bool) QueryStringSlice(key string, def []string) ([]string, bool) Query(key string) interface{} // 路由匹配中带的参数 // 形如 /book/:id ParamInt(key string, def int) (int, bool) ParamInt64(key string, def int64) (int64, bool) ParamFloat64(key string, def float64) (float64, bool) ParamFloat32(key string, def float32) (float32, bool) ParamBool(key string, def bool) (bool, bool) ParamString(key string, def string) (string, bool) Param(key string) interface{} // form表单中带的参数 FormInt(key string, def int) (int, bool) FormInt64(key string, def int64) (int64, bool) FormFloat64(key string, def float64) (float64, bool) FormFloat32(key string, def float32) (float32, bool) FormBool(key string, def bool) (bool, bool) FormString(key string, def string) (string, bool) FormStringSlice(key string, def []string) ([]string, bool) FormFile(key string) (*multipart.FileHeader, error) Form(key string) interface{} // json body BindJson(obj interface{}) error // xml body BindXml(obj interface{}) error // 其他格式 GetRawData() ([]byte, error) // 基础信息 Uri() string Method() string Host() string ClientIp() string // header Headers() map[string][]string Header(key string) (string, bool) // cookie Cookies() map[string]string Cookie(key string) (string, bool) }
type IResponse ¶
type IResponse interface { // Json输出 Json(obj interface{}) IResponse // Jsonp输出 Jsonp(obj interface{}) IResponse // xml输出 Xml(obj interface{}) IResponse // html输出 Html(template string, obj interface{}) IResponse // string Text(format string, values ...interface{}) IResponse // 重定向 Redirect(path string) IResponse // header SetHeader(key string, val string) IResponse // Cookie SetCookie(key string, val string, maxAge int, path, domain string, secure, httpOnly bool) IResponse // 设置状态码 SetStatus(code int) IResponse // 设置200状态 SetOkStatus() IResponse }
type LadeContainer ¶
type LadeContainer struct { Container // 强制要求 ladeContainer 实现 Container 接口 // contains filtered or unexported fields }
LadeContainer 是服务容器的具体实现
func NewLadeContainer ¶
func NewLadeContainer() *LadeContainer
func (*LadeContainer) Bind ¶
func (lade *LadeContainer) Bind(provider ServiceProvider) error
Bind将服务容器和关键字做了绑定
func (*LadeContainer) Make ¶
func (lade *LadeContainer) Make(key string) (interface{}, error)
调用内部make方法
func (*LadeContainer) MakeNew ¶
func (lade *LadeContainer) MakeNew(key string, params []interface{}) (interface{}, error)
MakeNew方式使用内部make初始化
func (*LadeContainer) MustMake ¶
func (lade *LadeContainer) MustMake(key string) interface{}
func (*LadeContainer) NameList ¶
func (lade *LadeContainer) NameList() []string
NameList 列出容器中所有provider的字符串凭证
func (*LadeContainer) PrintProviders ¶
func (lade *LadeContainer) PrintProviders() []string
PrintProviders 输出服务容器中注册的关键字
type ServiceProvider ¶
type ServiceProvider interface { // Register 在服务容器中注册了一个实例化服务的方法,是否在注册的时候就实例化这个服务,需要参考 IsDefer 接口。 Register(Container) NewInstance // Boot 在调用实例化服务的时候会调用,可以把一些准备工作:基础配置,初始化参数的操作放在这个里面。 // 如果 Boot 返回 error,整个服务实例化就会实例化失败,返回错误 Boot(Container) error // IsDefer 决定是否在注册的时候实例化这个服务,如果不是注册的时候实例化,那就是在第一次 make 的时候进行实例化操作 // false 表示不需要延迟实例化,在注册的时候就实例化。true 表示延迟实例化 IsDefer() bool // Params params 定义传递给 NewInstance 的参数,可以自定义多个,建议将 container 作为第一个参数 Params(Container) []interface{} // Name 代表了这个服务提供者的凭证 Name() string }
服务提供者需要的接口
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
func (*Tree) AddRouter ¶
func (tree *Tree) AddRouter(uri string, handlers ...ControllerHandler) error
添加路由节点
func (*Tree) FindHandler ¶
func (tree *Tree) FindHandler(uri string) []ControllerHandler
匹配uri,查找对应的handler
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package gin implements a HTTP web framework called gin.
|
Package gin implements a HTTP web framework called gin. |
provider
|
|
Click to show internal directories.
Click to hide internal directories.