mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
Nothing in codebase, just some MVC examples enhancements
Former-commit-id: 81f1121da0e7632ef3a0f7b78d6784ee1690eb7e
This commit is contained in:
@@ -55,32 +55,54 @@ func main() {
|
||||
type ExampleController struct {
|
||||
// if you build with go1.8 you have to use the mvc package always,
|
||||
// otherwise
|
||||
// you can simply use `iris.Controller`.
|
||||
mvc.Controller
|
||||
// you can, optionally
|
||||
// use the type alias `iris.C`,
|
||||
// same for
|
||||
// context.Context -> iris.Context,
|
||||
// mvc.Result -> iris.Result,
|
||||
// mvc.Response -> iris.Response,
|
||||
// mvc.View -> iris.View
|
||||
mvc.C
|
||||
}
|
||||
|
||||
// Get serves
|
||||
// Method: GET
|
||||
// Resource: http://localhost:8080
|
||||
func (c *ExampleController) Get() {
|
||||
c.ContentType = "text/html"
|
||||
c.Text = "<h1>Welcome!</h1>"
|
||||
func (c *ExampleController) Get() mvc.Result {
|
||||
return mvc.Response{
|
||||
ContentType: "text/html",
|
||||
Text: "<h1>Welcome</h1>",
|
||||
}
|
||||
}
|
||||
|
||||
// GetPing serves
|
||||
// Method: GET
|
||||
// Resource: http://localhost:8080/ping
|
||||
func (c *ExampleController) GetPing() {
|
||||
c.Text = "pong"
|
||||
func (c *ExampleController) GetPing() string {
|
||||
return "pong"
|
||||
}
|
||||
|
||||
// GetHello serves
|
||||
// Method: GET
|
||||
// Resource: http://localhost:8080/hello
|
||||
func (c *ExampleController) GetHello() {
|
||||
c.Ctx.JSON(iris.Map{"message": "Hello Iris!"})
|
||||
func (c *ExampleController) GetHello() interface{} {
|
||||
return map[string]string{"message": "Hello Iris!"}
|
||||
}
|
||||
|
||||
// GetUserBy serves
|
||||
// Method: GET
|
||||
// Resource: http://localhost:8080/user/{username:string}
|
||||
// By is a reserved "keyword" to tell the framework that you're going to
|
||||
// bind path parameters in the function's input arguments, and it also
|
||||
// helps to have "Get" and "GetBy" in the same controller.
|
||||
//
|
||||
// func (c *ExampleController) GetUserBy(username string) mvc.Result {
|
||||
// return mvc.View{
|
||||
// Name: "user/username.html",
|
||||
// Data: username,
|
||||
// }
|
||||
// }
|
||||
|
||||
/* Can use more than one, the factory will make sure
|
||||
that the correct http methods are being registered for each route
|
||||
for this controller, uncomment these if you want:
|
||||
|
||||
Reference in New Issue
Block a user