1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-01 09:17:02 +00:00

Update to version 12.1.7

Former-commit-id: 3e214ab6b6da4d1c6e4a66180a4ccfa61c0879ae
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-02-10 19:40:17 +02:00
parent ea589b1276
commit 10f280af63
15 changed files with 357 additions and 123 deletions

View File

@@ -143,6 +143,7 @@ Navigate through examples for a better understanding.
- [Writing a middleware](routing/writing-a-middleware)
* [per-route](routing/writing-a-middleware/per-route/main.go)
* [globally](routing/writing-a-middleware/globally/main.go)
- [Route Register Rule](routing/route-register-rule/main.go) **NEW**
### Versioning

View File

@@ -3,6 +3,6 @@ module app
go 1.13
require (
github.com/kataras/iris/v12 v12.1.6
github.com/kataras/iris/v12 v12.1.7
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
)

View File

@@ -0,0 +1,41 @@
package main
import "github.com/kataras/iris/v12"
func main() {
app := newApp()
// Navigate through https://github.com/kataras/iris/issues/1448 for details.
//
// GET: http://localhost:8080
// POST, PUT, DELETE, CONNECT, HEAD, PATCH, OPTIONS, TRACE : http://localhost:8080
app.Listen(":8080")
}
func newApp() *iris.Application {
app := iris.New()
// Skip and do NOT override existing regitered route, continue normally.
// Applies to a Party and its children, in this case the whole application's routes.
app.SetRegisterRule(iris.RouteSkip)
/* Read also:
// The default behavior, will override the getHandler to anyHandler on `app.Any` call.
app.SetRegistRule(iris.RouteOverride)
// Stops the execution and fires an error before server boot.
app.SetRegisterRule(iris.RouteError)
*/
app.Get("/", getHandler)
// app.Any does NOT override the previous GET route because of `iris.RouteSkip` rule.
app.Any("/", anyHandler)
return app
}
func getHandler(ctx iris.Context) {
ctx.Writef("From %s", ctx.GetCurrentRoute().Trace())
}
func anyHandler(ctx iris.Context) {
ctx.Writef("From %s", ctx.GetCurrentRoute().Trace())
}

View File

@@ -0,0 +1,22 @@
package main
import (
"testing"
"github.com/kataras/iris/v12/core/router"
"github.com/kataras/iris/v12/httptest"
)
func TestRouteRegisterRuleExample(t *testing.T) {
app := newApp()
e := httptest.New(t, app)
for _, method := range router.AllMethods {
tt := e.Request(method, "/").Expect().Status(httptest.StatusOK).Body()
if method == "GET" {
tt.Equal("From [./main.go:28] GET: / -> github.com/kataras/iris/v12/_examples/routing/route-register-rule.getHandler()")
} else {
tt.Equal("From [./main.go:30] " + method + ": / -> github.com/kataras/iris/v12/_examples/routing/route-register-rule.anyHandler()")
}
}
}

View File

@@ -1,25 +1,55 @@
<a href="{{urlpath "my-page1"}}">/mypath</a>
<br />
<br />
<html>
<a href="{{urlpath "my-page2" "theParam1" "theParam2"}}">/mypath2/{paramfirst}/{paramsecond}</a>
<br />
<br />
<head>
<title>template_html_3</title>
<style>
a {
color: #0f7afc;
border-bottom-color: rgba(15, 122, 252, 0.2);
text-decoration: none
}
<a href="{{urlpath "my-page3" "theParam1" "theParam2AfterStatic"}}">/mypath3/{paramfirst}/statichere/{paramsecond}</a>
<br />
<br />
a:hover {
color: #cf0000;
border-bottom-color: rgba(208, 64, 0, 0.2);
text-decoration: none
}
<a href="{{urlpath "my-page4" "theParam1" "theparam2AfterStatic" "otherParam" "matchAnything"}}">
/mypath4/{paramfirst}/statichere/{paramsecond}/{otherparam}/{something:path}</a>
<br />
<br />
a:visited {
color: #800080;
border-bottom-color: rgba(128, 0, 128, 0.2);
text-decoration: none
}
</style>
</head>
<a href="{{urlpath "my-page5" "theParam1" "theParam2Afterstatichere" "otherParam" "matchAnythingAfterStatic"}}">
/mypath5/{paramfirst}/statichere/{paramsecond}/{otherparam}/anything/{anything:path}</a>
<br />
<br />
<body>
<a href={{urlpath "my-page6" .ParamsAsArray }}>
/mypath6/{paramfirst}/{paramsecond}/statichere/{paramThirdAfterStatic}
</a>
<a href="{{urlpath "my-page1"}}">/mypath</a>
<br />
<br />
<a href="{{urlpath "my-page2" "theParam1" "theParam2"}}">/mypath2/{paramfirst}/{paramsecond}</a>
<br />
<br />
<a href="{{urlpath "my-page3" "theParam1" "theParam2AfterStatic"}}">/mypath3/{paramfirst}/statichere/{paramsecond}</a>
<br />
<br />
<a href="{{urlpath "my-page4" "theParam1" "theparam2AfterStatic" "otherParam" "matchAnything"}}">
/mypath4/{paramfirst}/statichere/{paramsecond}/{otherparam}/{something:path}</a>
<br />
<br />
<a href="{{urlpath "my-page5" "theParam1" "theParam2Afterstatichere" "otherParam" "matchAnythingAfterStatic"}}">
/mypath5/{paramfirst}/statichere/{paramsecond}/{otherparam}/anything/{anything:path}</a>
<br />
<br />
<a href={{urlpath "my-page6" .ParamsAsArray }}>
/mypath6/{paramfirst}/{paramsecond}/statichere/{paramThirdAfterStatic}
</a>
</body>
</html>