mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 08:16:28 +01:00
ℹ️ add mvc 'ByWildcard' example as requested at #1459
Although, we already had a usage of this as a test at mvc/controller_test.go#testControllerRelPathFromFunc Former-commit-id: 66343933aa86750615ab89767f149f6636d03be7
This commit is contained in:
parent
bb66c10ad3
commit
409f83ca66
|
@ -162,6 +162,8 @@ Navigate through examples for a better understanding.
|
||||||
### MVC
|
### MVC
|
||||||
|
|
||||||
- [Hello world](mvc/hello-world/main.go)
|
- [Hello world](mvc/hello-world/main.go)
|
||||||
|
- [Basic](mvc/basic/main.go)
|
||||||
|
- [Basic: wildcard](mvc/basic/wildcard/main.go) **NEW**
|
||||||
- [Regexp](mvc/regexp/main.go)
|
- [Regexp](mvc/regexp/main.go)
|
||||||
- [Session Controller](mvc/session-controller/main.go)
|
- [Session Controller](mvc/session-controller/main.go)
|
||||||
- [Overview - Plus Repository and Service layers](mvc/overview)
|
- [Overview - Plus Repository and Service layers](mvc/overview)
|
||||||
|
|
41
_examples/mvc/basic/wildcard/main.go
Normal file
41
_examples/mvc/basic/wildcard/main.go
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
"github.com/kataras/iris/v12/mvc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := iris.New()
|
||||||
|
usersRouter := app.Party("/users")
|
||||||
|
mvc.New(usersRouter).Handle(new(myController))
|
||||||
|
// Same as:
|
||||||
|
// usersRouter.Get("/{p:path}", func(ctx iris.Context) {
|
||||||
|
// wildcardPathParameter := ctx.Params().Get("p")
|
||||||
|
// ctx.JSON(response{
|
||||||
|
// Message: "The path parameter is: " + wildcardPathParameter,
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
|
||||||
|
/*
|
||||||
|
curl --location --request GET 'http://localhost:8080/users/path_segment_1/path_segment_2'
|
||||||
|
|
||||||
|
Expected Output:
|
||||||
|
{
|
||||||
|
"message": "The wildcard is: path_segment_1/path_segment_2"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
app.Listen(":8080")
|
||||||
|
}
|
||||||
|
|
||||||
|
type myController struct{}
|
||||||
|
|
||||||
|
type response struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *myController) GetByWildcard(wildcardPathParameter string) response {
|
||||||
|
return response{
|
||||||
|
Message: "The path parameter is: " + wildcardPathParameter,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user