mirror of
https://github.com/kataras/iris.git
synced 2026-01-04 10:47:20 +00:00
Update to 8.2.5 | Say Hello to Controllers. Read HISTORY.md
Former-commit-id: 70f8619440497d132362da86c5187bcc57f8687b
This commit is contained in:
@@ -100,6 +100,62 @@ type Party interface {
|
||||
// (Get,Post,Put,Head,Patch,Options,Connect,Delete).
|
||||
Any(registeredPath string, handlers ...context.Handler) []*Route
|
||||
|
||||
// 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 this method is a 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` .
|
||||
//
|
||||
// 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 persistence data:
|
||||
//
|
||||
// type UserController struct {
|
||||
// Controller
|
||||
//
|
||||
// CreatedAt time.Time `iris:"persistence"`
|
||||
// Title string `iris:"persistence"`
|
||||
// DB *DB `iris:"persistence"`
|
||||
// }
|
||||
//
|
||||
// // Get serves using the User controller when HTTP Method is "GET".
|
||||
// func (c *UserController) Get() {
|
||||
// c.Tmpl = "user/index.html"
|
||||
// c.Data["title"] = c.Title
|
||||
// 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}", &UserController{
|
||||
// CreatedAt: time.Now(),
|
||||
// Title: "User page",
|
||||
// DB: yourDB,
|
||||
// })
|
||||
//
|
||||
// Read more at `router#Controller`.
|
||||
Controller(relativePath string, controller interface{}) []*Route
|
||||
|
||||
// StaticHandler returns a new Handler which is ready
|
||||
// to serve all kind of static files.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user