mirror of
https://github.com/kataras/iris.git
synced 2026-01-02 17:57:11 +00:00
Update to 8.2.5 | Say Hello to Controllers. Read HISTORY.md
Former-commit-id: 70f8619440497d132362da86c5187bcc57f8687b
This commit is contained in:
76
context.go
76
context.go
@@ -10,6 +10,16 @@ import (
|
||||
|
||||
// TODO: When go 1.9 will be released
|
||||
// split this file in order to separate the concepts.
|
||||
//
|
||||
// Files should change after go1.9 final release:
|
||||
// README.md: Hello World with Go 1.9
|
||||
// core/host/supervisor.go
|
||||
// context.go
|
||||
// _examples/hello-world/main_go19.go
|
||||
// _examples/routing/mvc/controllers/index_go19.go
|
||||
// _examples/routing/mvc/controllers/user_go19.go
|
||||
// _examples/routing/mvc/main_go19.go
|
||||
// _examples/tutorial/mvc-from-scratch/README.md
|
||||
type (
|
||||
// Context is the midle-man server's "object" for the clients.
|
||||
//
|
||||
@@ -49,4 +59,70 @@ type (
|
||||
//
|
||||
// A shortcut for the `core/router#Party`, useful when `PartyFunc` is being used.
|
||||
Party = router.Party
|
||||
// Controller is the base controller for the high level controllers instances.
|
||||
//
|
||||
// This base controller is used as an alternative way of building
|
||||
// APIs, 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"`
|
||||
// are being persistence and kept between the different requests,
|
||||
// meaning that these data will not be reset-ed on each new request,
|
||||
// they will be the same for all requests.
|
||||
//
|
||||
// An Example Controller can be:
|
||||
//
|
||||
// type IndexController struct {
|
||||
// iris.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 {
|
||||
// iris.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,
|
||||
// })
|
||||
//
|
||||
// Look `core/router#APIBuilder#Controller` method too.
|
||||
//
|
||||
// A shortcut for the `core/router#Controller`,
|
||||
// useful when `app.Controller` is being used.
|
||||
//
|
||||
// A Controller can be declared by importing
|
||||
// the "github.com/kataras/iris/core/router"
|
||||
// package for machines that have not installed go1.9 yet.
|
||||
Controller = router.Controller
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user