-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Former-commit-id: 4d39e8a764a7c0d91b19a3710d8afe6c8c208c62
- Loading branch information
Showing
14 changed files
with
145 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
12.1.5:https://github.com/kataras/iris/releases/tag/v12.1.5 | ||
12.1.6:https://github.com/kataras/iris/releases/tag/v12.1.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Package main an example on how to naming your routes & use the custom 'url path' Jet Template Engine. | ||
package main | ||
|
||
import ( | ||
"github.com/kataras/iris/v12" | ||
) | ||
|
||
func main() { | ||
app := iris.New() | ||
app.RegisterView(iris.Jet("./views", ".jet").Reload(true)) | ||
|
||
mypathRoute := app.Get("/mypath", writePathHandler) | ||
mypathRoute.Name = "my-page1" | ||
|
||
mypath2Route := app.Get("/mypath2/{paramfirst}/{paramsecond}", writePathHandler) | ||
mypath2Route.Name = "my-page2" | ||
|
||
mypath3Route := app.Get("/mypath3/{paramfirst}/statichere/{paramsecond}", writePathHandler) | ||
mypath3Route.Name = "my-page3" | ||
|
||
mypath4Route := app.Get("/mypath4/{paramfirst}/statichere/{paramsecond}/{otherparam}/{something:path}", writePathHandler) | ||
// same as: app.Get("/mypath4/:paramfirst/statichere/:paramsecond/:otherparam/*something", writePathHandler) | ||
mypath4Route.Name = "my-page4" | ||
|
||
// same with Handle/Func | ||
mypath5Route := app.Handle("GET", "/mypath5/{paramfirst}/statichere/{paramsecond}/{otherparam}/anything/{something:path}", writePathHandler) | ||
mypath5Route.Name = "my-page5" | ||
|
||
mypath6Route := app.Get("/mypath6/{paramfirst}/{paramsecond}/statichere/{paramThirdAfterStatic}", writePathHandler) | ||
mypath6Route.Name = "my-page6" | ||
|
||
app.Get("/", func(ctx iris.Context) { | ||
// for /mypath6... | ||
paramsAsArray := []string{"theParam1", "theParam2", "paramThirdAfterStatic"} | ||
ctx.ViewData("ParamsAsArray", paramsAsArray) | ||
if err := ctx.View("page.jet"); err != nil { | ||
panic(err) | ||
} | ||
}) | ||
|
||
app.Get("/redirect/{namedRoute}", func(ctx iris.Context) { | ||
routeName := ctx.Params().Get("namedRoute") | ||
r := app.GetRoute(routeName) | ||
if r == nil { | ||
ctx.StatusCode(iris.StatusNotFound) | ||
ctx.Writef("Route with name %s not found", routeName) | ||
return | ||
} | ||
|
||
println("The path of " + routeName + "is: " + r.Path) | ||
// if routeName == "my-page1" | ||
// prints: The path of of my-page1 is: /mypath | ||
// if it's a path which takes named parameters | ||
// then use "r.ResolvePath(paramValuesHere)" | ||
ctx.Redirect(r.Path) | ||
// http://localhost:8080/redirect/my-page1 will redirect to -> http://localhost:8080/mypath | ||
}) | ||
|
||
// http://localhost:8080 | ||
// http://localhost:8080/redirect/my-page1 | ||
app.Run(iris.Addr(":8080")) | ||
} | ||
|
||
func writePathHandler(ctx iris.Context) { | ||
ctx.Writef("Hello from %s.", ctx.Path()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.