Documentation ¶
Index ¶
- Variables
- func DefaultNext(ctx Context)
- func Do(ctx Context, handlers Handlers)
- func HandlerName(h Handler) string
- func IsController(i interface{}) bool
- func IsOrmModel(i interface{}) bool
- func Mix(method string, path interface{}) string
- type Application
- type BaseMongoModel
- type BaseMysqlOrmModel
- func (m *BaseMysqlOrmModel) DB() *gorm.DB
- func (m *BaseMysqlOrmModel) Del()
- func (m *BaseMysqlOrmModel) DelInTx(tx *gorm.DB)
- func (m *BaseMysqlOrmModel) FieldFromString(s string, f interface{})
- func (m *BaseMysqlOrmModel) FieldToString(f interface{}) string
- func (m *BaseMysqlOrmModel) Init(db *gorm.DB, self interface{})
- func (m *BaseMysqlOrmModel) Sync(cols ...interface{})
- func (m *BaseMysqlOrmModel) SyncInTx(tx *gorm.DB, cols ...interface{})
- type Context
- type Controller
- type Handler
- type Handlers
- type MessageBodyWrapper
- type MysqlOrmModel
- type Pool
- type Router
- type RouterBuilder
- type RpcContext
- type ServiceContext
- type WebApiContext
Constants ¶
This section is empty.
Variables ¶
var Next = DefaultNext
Next is the function that executed when `ctx.Next()` is called. It can be changed to a customized one if needed (very advanced usage).
See `DefaultNext` for more information about this and why it's exported like this.
Functions ¶
func DefaultNext ¶
func DefaultNext(ctx Context)
DefaultNext is the default function that executed on each middleware if `ctx.Next()` is called.
DefaultNext calls the next handler from the handlers chain by registration order, it should be used inside a middleware.
It can be changed to a customized one if needed (very advanced usage).
Developers are free to customize the whole or part of the Context's implementation by implementing a new `context.Context` (see https://github.com/kataras/iris/tree/master/_examples/routing/custom-context) or by just override the `context.Next` package-level field, `context.DefaultNext` is exported in order to be able for developers to merge your customized version one with the default behavior as well.
func Do ¶
Do calls the SetHandlers(handlers) and executes the first handler, handlers should not be empty.
It's used by the router, developers may use that to replace and execute handlers immediately.
func HandlerName ¶
HandlerName returns the name, the handler function informations. Same as `context.HandlerName`.
func IsController ¶
func IsController(i interface{}) bool
func IsOrmModel ¶
func IsOrmModel(i interface{}) bool
Types ¶
type Application ¶
type Application interface { Name() string Run() ShutDown() // mvc objects RegisterController(...interface{}) // modules AddModule(module.Module) GetModule(module.Module) module.Module RPC() module.RPCModule Service() module.ServiceModule Log() module.LogModule MySql() module.MySqlModule Mongo() module.MongoModule Config() utils.ValueMap // 使用中间件,中间件将在其他Handler之前执行 Use(middleware ...Handler) GlobalMiddleWares() Handlers RpcCtxPool() *Pool ServiceCtxPool() *Pool WebApiCtxPool() *Pool // 系统配置 BingoConfig() *config.BingoConfig // 获取运行环境 Env() string }
func New ¶
func New() Application
type BaseMongoModel ¶
type BaseMysqlOrmModel ¶
type BaseMysqlOrmModel struct { Id uint32 `gorm:"primary_key"` // contains filtered or unexported fields }
func (*BaseMysqlOrmModel) DB ¶
func (m *BaseMysqlOrmModel) DB() *gorm.DB
func (*BaseMysqlOrmModel) FieldFromString ¶
func (m *BaseMysqlOrmModel) FieldFromString(s string, f interface{})
func (*BaseMysqlOrmModel) FieldToString ¶
func (m *BaseMysqlOrmModel) FieldToString(f interface{}) string
func (*BaseMysqlOrmModel) Init ¶
func (m *BaseMysqlOrmModel) Init(db *gorm.DB, self interface{})
func (*BaseMysqlOrmModel) SyncInTx ¶
func (m *BaseMysqlOrmModel) SyncInTx(tx *gorm.DB, cols ...interface{})
更新到数据库
type Context ¶
type Context interface { // BeginRequest is executing once for each request // it should prepare the (new or acquired from pool) context's fields for the new request. // // To follow the iris' flow, developer should: // 1. reset handlers to nil // 2. reset values to empty // 3. reset sessions to nil // 4. reset response writer to the http.ResponseWriter // 5. reset request to the *http.Request // and any other optional steps, depends on dev's application type. BeginRequest() // EndRequest is executing once after a response to the request was sent and this context is useless or released. // // To follow the iris' flow, developer should: // 1. flush the response writer's result // 2. release the response writer // and any other optional steps, depends on dev's application type. EndRequest() // returns the unique id Id() uint32 // Do calls the SetHandlers(handlers) // and executes the first handler, // handlers should not be empty. // // It's used by the router, developers may use that // to replace and execute handlers immediately. Do(Handlers) // AddHandler can add handler(s) // to the current request in serve-time, // these handlers are not persistenced to the router. // // Router is calling this function to add the route's handler. // If AddHandler called then the handlers will be inserted // to the end of the already-defined route's handler. // AddHandler(...Handler) // SetHandlers replaces all handlers with the new. SetHandlers(Handlers) // Handlers keeps tracking of the current handlers. Handlers() Handlers // HandlerIndex sets the current index of the // current context's handlers chain. // If -1 passed then it just returns the // current handler index without change the current index.rns that index, useless return value. // // Look Handlers(), Next() and StopExecution() too. HandlerIndex(n int) int // Proceed is an alternative way to check if a particular handler // has been executed and called the `ctx.Next` function inside it. // This is useful only when you run a handler inside // another handler. It justs checks for before index and the after index. // // A usecase example is when you want to execute a middleware // inside controller's `BeginRequest` that calls the `ctx.Next` inside it. // The Controller looks the whole flow (BeginRequest, method handler, EndRequest) // as one handler, so `ctx.Next` will not be reflected to the method handler // if called from the `BeginRequest`. // // Although `BeginRequest` should NOT be used to call other handlers, // the `BeginRequest` has been introduced to be able to set // common data to all method handlers before their execution. // Controllers can accept middleware(s) from the MVC's Application's Router as normally. // // That said let's see an example of `ctx.Proceed`: // // var authMiddleware = basicauth.New(basicauth.Config{ // Users: map[string]string{ // "admin": "password", // }, // }) // // func (c *UsersController) BeginRequest(ctx iris.Context) { // if !ctx.Proceed(authMiddleware) { // ctx.StopExecution() // } // } // This Get() will be executed in the same handler as `BeginRequest`, // internally controller checks for `ctx.StopExecution`. // So it will not be fired if BeginRequest called the `StopExecution`. // func(c *UsersController) Get() []models.User { // return c.Service.GetAll() //} // Alternative way is `!ctx.IsStopped()` if middleware make use of the `ctx.StopExecution()` on failure. Proceed(Handler) bool // HandlerName returns the current handler's name, helpful for debugging. HandlerName() string // Next calls all the next handler from the handlers chain, // it should be used inside a middleware. // // Note: Custom context should override this method in order to be able to pass its own context.Context implementation. Next() // NextOr checks if chain has a next handler, if so then it executes it // otherwise it sets a new chain assigned to this Context based on the given handler(s) // and executes its first handler. // // Returns true if next handler exists and executed, otherwise false. // // Note that if no next handler found and handlers are missing then // it sends a Status Not Found (404) to the client and it stops the execution. NextOr(handlers ...Handler) bool // NextOrNotFound checks if chain has a next handler, if so then it executes it // otherwise it sends a Status Not Found (404) to the client and stops the execution. // // Returns true if next handler exists and executed, otherwise false. NextOrNotFound() bool // NextHandler returns (it doesn't execute) the next handler from the handlers chain. // // Use .Skip() to skip this handler if needed to execute the next of this returning handler. NextHandler() Handler // Skip skips/ignores the next handler from the handlers chain, // it should be used inside a middleware. Skip() // StopExecution if called then the following .Next calls are ignored, // as a result the next handlers in the chain will not be fire. StopExecution() // IsStopped checks and returns true if the current position of the Context is 255, // means that the StopExecution() was called. IsStopped() bool App() Application LogE(format string, v ...interface{}) LogD(format string, v ...interface{}) LogW(format string, v ...interface{}) LogI(format string, v ...interface{}) Logger(name string) log.Logger }
func NewContext ¶
func NewContext(app Application) Context
NewContext returns the default, internal, context implementation. You may use this function to embed the default context implementation to a custom one.
This context is received by the context pool.
type Controller ¶
type Controller interface {
Route(builder RouterBuilder)
}
type Handlers ¶
type Handlers []Handler
Handlers is just a type of slice of []Handler.
See `Handler` for more.
type MessageBodyWrapper ¶
type MessageBodyWrapper struct { RawContent net.MessageBody Codec codec.Codec }
func (*MessageBodyWrapper) Unmarshal ¶
func (c *MessageBodyWrapper) Unmarshal(v interface{})
type MysqlOrmModel ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is the context pool, it's used inside router and the framework by itself.
It's the only one real implementation inside this package because it used widely.
func (*Pool) Attach ¶
Attach changes the pool's return value Context.
The new Context should explicitly define the `Next()` and `Do(context.Handlers)` functions.
func (*Pool) Release ¶
Release puts a Context back to its pull, this function releases its resources. See Acquire.
func (*Pool) ReleaseLight ¶
ReleaseLight will just release the object back to the pool, but the clean method is caller's responsibility now, currently this is only used on `SPABuilder`.
type Router ¶
type RouterBuilder ¶
type RpcContext ¶
func (*RpcContext) Args ¶
func (c *RpcContext) Args(i interface{})
func (*RpcContext) CheckError ¶
func (c *RpcContext) CheckError(e error)
func (*RpcContext) Do ¶
func (c *RpcContext) Do(handlers Handlers)
The only one important if you will override the Context with an embedded context.Context inside it. Required in order to run the handlers via this "*MyContext".
func (*RpcContext) Next ¶
func (c *RpcContext) Next()
The second one important if you will override the Context with an embedded context.Context inside it. Required in order to run the chain of handlers via this "*MyContext".
func (*RpcContext) Return ¶
func (c *RpcContext) Return(i interface{})
func (*RpcContext) ReturnNil ¶
func (c *RpcContext) ReturnNil()
type ServiceContext ¶
type ServiceContext struct { Context Conn net.Conn MessageType int32 MessageGroup int32 MessageExtra int32 MessageId int32 // unpacked id MessageBody *MessageBodyWrapper Codec codec.Codec }
func (*ServiceContext) Ack ¶
func (c *ServiceContext) Ack(body interface{})
func (*ServiceContext) Cmd ¶
func (c *ServiceContext) Cmd(body interface{})
Note that: just send to the requester
func (*ServiceContext) Do ¶
func (c *ServiceContext) Do(handlers Handlers)
The only one important if you will override the Context with an embedded context.Context inside it. Required in order to run the handlers via this "*MyContext".
func (*ServiceContext) Next ¶
func (c *ServiceContext) Next()
The second one important if you will override the Context with an embedded context.Context inside it. Required in order to run the chain of handlers via this "*MyContext".
func (*ServiceContext) Ntf ¶
func (c *ServiceContext) Ntf(body interface{})
Note that: just send to the requester
type WebApiContext ¶
type WebApiContext struct { Context RequestCtx *fasthttp.RequestCtx Codec codec.Codec }
func (*WebApiContext) Do ¶
func (c *WebApiContext) Do(handlers Handlers)
The only one important if you will override the Context with an embedded context.Context inside it. Required in order to run the handlers via this "*MyContext".
func (*WebApiContext) Next ¶
func (c *WebApiContext) Next()
The second one important if you will override the Context with an embedded context.Context inside it. Required in order to run the chain of handlers via this "*MyContext".
func (*WebApiContext) RequestBody ¶
func (c *WebApiContext) RequestBody(body interface{})
func (*WebApiContext) ResponseFailed ¶
func (c *WebApiContext) ResponseFailed(reason string)
func (*WebApiContext) ResponseOK ¶
func (c *WebApiContext) ResponseOK(body interface{})