mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
remove the old 'mvc' folder - examples are not changed yet - add the 'di' package inside the mvc2 package - which will be renamed to 'mvc' on the next commit - new mvc.Application and some dublications removed - The new version will be version 9 because it will contain breaking changes (not to the end-developer's controllers but to the API they register them) - get ready for 'Christmas Edition' for believers
Former-commit-id: c7114233dee90ee308c0a3e77ec2ad0c361094b8
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/core/errors"
|
||||
"github.com/kataras/iris/core/router/macro"
|
||||
"github.com/kataras/iris/mvc/activator"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -478,85 +477,6 @@ func (api *APIBuilder) Any(relativePath string, handlers ...context.Handler) (ro
|
||||
return
|
||||
}
|
||||
|
||||
// Controller registers a `Controller` instance and returns the registered Routes.
|
||||
// The "controller" receiver should embed a field of `Controller` in order
|
||||
// to be compatible Iris `Controller`.
|
||||
//
|
||||
// It's just an alternative way of building an API for a specific
|
||||
// path, the controller can register all type of http methods.
|
||||
//
|
||||
// Keep note that controllers are bit slow
|
||||
// because of the reflection use however it's as fast as possible because
|
||||
// it does preparation before the serve-time handler but still
|
||||
// remains slower than the low-level handlers
|
||||
// such as `Handle, Get, Post, Put, Delete, Connect, Head, Trace, Patch`.
|
||||
//
|
||||
//
|
||||
// All fields that are tagged with iris:"persistence"` or binded
|
||||
// are being persistence and kept the same between the different requests.
|
||||
//
|
||||
// An Example Controller can be:
|
||||
//
|
||||
// type IndexController struct {
|
||||
// Controller
|
||||
// }
|
||||
//
|
||||
// func (c *IndexController) Get() {
|
||||
// c.Tmpl = "index.html"
|
||||
// c.Data["title"] = "Index page"
|
||||
// c.Data["message"] = "Hello world!"
|
||||
// }
|
||||
//
|
||||
// Usage: app.Controller("/", new(IndexController))
|
||||
//
|
||||
//
|
||||
// Another example with bind:
|
||||
//
|
||||
// type UserController struct {
|
||||
// Controller
|
||||
//
|
||||
// DB *DB
|
||||
// CreatedAt time.Time
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // Get serves using the User controller when HTTP Method is "GET".
|
||||
// func (c *UserController) Get() {
|
||||
// c.Tmpl = "user/index.html"
|
||||
// c.Data["title"] = "User Page"
|
||||
// c.Data["username"] = "kataras " + c.Params.Get("userid")
|
||||
// c.Data["connstring"] = c.DB.Connstring
|
||||
// c.Data["uptime"] = time.Now().Sub(c.CreatedAt).Seconds()
|
||||
// }
|
||||
//
|
||||
// Usage: app.Controller("/user/{id:int}", new(UserController), db, time.Now())
|
||||
// Note: Binded values of context.Handler type are being recognised as middlewares by the router.
|
||||
//
|
||||
// Read more at `/mvc#Controller`.
|
||||
func (api *APIBuilder) Controller(relativePath string, controller activator.BaseController,
|
||||
bindValues ...interface{}) (routes []*Route) {
|
||||
|
||||
registerFunc := func(method string, ifRelPath string, handlers ...context.Handler) {
|
||||
relPath := relativePath + ifRelPath
|
||||
r := api.HandleMany(method, relPath, handlers...)
|
||||
routes = append(routes, r...)
|
||||
}
|
||||
|
||||
// bind any values to the controller's relative fields
|
||||
// and set them on each new request controller,
|
||||
// binder is an alternative method
|
||||
// of the persistence data control which requires the
|
||||
// user already set the values manually to controller's fields
|
||||
// and tag them with `iris:"persistence"`.
|
||||
//
|
||||
// don't worry it will never be handled if empty values.
|
||||
if err := activator.Register(controller, bindValues, registerFunc); err != nil {
|
||||
api.reporter.Add("%v for path: '%s'", err, relativePath)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// StaticCacheDuration expiration duration for INACTIVE file handlers, it's the only one global configuration
|
||||
// which can be changed.
|
||||
var StaticCacheDuration = 20 * time.Second
|
||||
|
||||
Reference in New Issue
Block a user