1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-19 10:57:05 +00:00
Former-commit-id: da3ffd7b32daa12b17ad2863cb55e9d15ec9943a
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-07-30 18:02:02 +03:00
parent 04834484ff
commit 970279deb8
6 changed files with 21 additions and 6 deletions

View File

@@ -18,8 +18,8 @@ func newApp() *iris.Application {
//
// Third receiver should contains the route's handler(s), they are executed by order.
app.Handle("GET", "/", func(ctx iris.Context) {
// navigate to the middle of $GOPATH/src/github.com/kataras/iris/context/context.go
// to overview all context's method (there a lot of them, read that and you will learn how iris works too)
// navigate to the https://github.com/kataras/iris/wiki/Routing-context-methods
// to overview all context's method.
ctx.HTML("Hello from " + ctx.Path()) // Hello from /
})
@@ -28,6 +28,10 @@ func newApp() *iris.Application {
})
// Different path parameters types in the same path.
app.Get("/u/{p:path}", func(ctx iris.Context) {
ctx.Writef(":string, :int, :uint, :alphabetical and :path in the same path pattern.")
})
app.Get("/u/{username:string}", func(ctx iris.Context) {
ctx.Writef("before username (string), current route name: %s\n", ctx.RouteName())
ctx.Next()
@@ -57,6 +61,7 @@ func newApp() *iris.Application {
})
/*
/u/some/path/here maps to :path
/u/abcd maps to :alphabetical (if :alphabetical registered otherwise :string)
/u/42 maps to :uint (if :uint registered otherwise :int)
/u/-1 maps to :int (if :int registered otherwise :string)
@@ -173,6 +178,7 @@ func main() {
// http://localhost:8080/u/42
// http://localhost:8080/u/-1
// http://localhost:8080/u/abcd123
// http://localhost:8080/u/some/path/here
//
// if hosts edited:
// http://v1.localhost:8080

View File

@@ -29,6 +29,7 @@ func TestRoutingBasic(t *testing.T) {
expectedIndexResponse = "Hello from /"
expectedHomeResponse = `Same as app.Handle("GET", "/", [...])`
expectedUpathResponse = ":string, :int, :uint, :alphabetical and :path in the same path pattern."
expectedUStringResponse = expectedUResponse("username", "string", "abcd123")
expectedUIntResponse = expectedUResponse("id", "int", "-1")
expectedUUintResponse = expectedUResponse("uid", "uint", "42")
@@ -56,6 +57,8 @@ func TestRoutingBasic(t *testing.T) {
e.GET("/home").Expect().Status(httptest.StatusOK).
Body().Equal(expectedHomeResponse)
e.GET("/u/some/path/here").Expect().Status(httptest.StatusOK).
Body().Equal(expectedUpathResponse)
e.GET("/u/abcd123").Expect().Status(httptest.StatusOK).
Body().Equal(expectedUStringResponse)
e.GET("/u/-1").Expect().Status(httptest.StatusOK).