Skip to content

Commit 409f83c

Browse files
committed
ℹ️ add mvc 'ByWildcard' example as requested at kataras#1459
Although, we already had a usage of this as a test at mvc/controller_test.go#testControllerRelPathFromFunc Former-commit-id: 66343933aa86750615ab89767f149f6636d03be7
1 parent bb66c10 commit 409f83c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

_examples/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ Navigate through examples for a better understanding.
162162
### MVC
163163

164164
- [Hello world](mvc/hello-world/main.go)
165+
- [Basic](mvc/basic/main.go)
166+
- [Basic: wildcard](mvc/basic/wildcard/main.go) **NEW**
165167
- [Regexp](mvc/regexp/main.go)
166168
- [Session Controller](mvc/session-controller/main.go)
167169
- [Overview - Plus Repository and Service layers](mvc/overview)

_examples/mvc/basic/wildcard/main.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package main
2+
3+
import (
4+
"github.com/kataras/iris/v12"
5+
"github.com/kataras/iris/v12/mvc"
6+
)
7+
8+
func main() {
9+
app := iris.New()
10+
usersRouter := app.Party("/users")
11+
mvc.New(usersRouter).Handle(new(myController))
12+
// Same as:
13+
// usersRouter.Get("/{p:path}", func(ctx iris.Context) {
14+
// wildcardPathParameter := ctx.Params().Get("p")
15+
// ctx.JSON(response{
16+
// Message: "The path parameter is: " + wildcardPathParameter,
17+
// })
18+
// })
19+
20+
/*
21+
curl --location --request GET 'http://localhost:8080/users/path_segment_1/path_segment_2'
22+
23+
Expected Output:
24+
{
25+
"message": "The wildcard is: path_segment_1/path_segment_2"
26+
}
27+
*/
28+
app.Listen(":8080")
29+
}
30+
31+
type myController struct{}
32+
33+
type response struct {
34+
Message string `json:"message"`
35+
}
36+
37+
func (c *myController) GetByWildcard(wildcardPathParameter string) response {
38+
return response{
39+
Message: "The path parameter is: " + wildcardPathParameter,
40+
}
41+
}

0 commit comments

Comments
 (0)