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

@ -55,4 +55,4 @@ app.Get("/path", func(ctx iris.Context){
# Tu, 23 July 2019 | v11.2.0
Read about the new release at: https://dev.to/kataras/iris-version-11-2-released-22bc
Read about the new release at: https://www.facebook.com/iris.framework/posts/3276606095684693

View File

@ -8,7 +8,7 @@ Iris is a fast, simple yet fully featured and very efficient web framework for G
Learn what [others say about Iris](https://iris-go.com/testimonials/) and **star** this github repository.
> Version 11.2 **released!** [Spread the news](https://dev.to/kataras/iris-version-11-2-released-22bc).
> Version 11.2 **released!** [Spread the news](https://www.facebook.com/iris.framework/posts/3276606095684693).
## Learning Iris
@ -53,9 +53,10 @@ For a more detailed technical documentation you can head over to our [godocs](ht
### Do you like to read while traveling?
<a href="https://bit.ly/iris-req-book"> <img alt="Book cover" src="https://iris-go.com/images/iris-book-cover.jpg" width="200" /> </a>
You can [request](https://bit.ly/iris-req-book) a PDF version and online access of the **E-Book** today and be participated in the development of Iris.
[![https://iris-go.com/images/iris-book-overview.png](https://iris-go.com/images/iris-book-overview.png)](https://bit.ly/iris-req-book)
## Contributing

View File

@ -8,7 +8,7 @@ Iris 是基于 Go 编写的一个快速,简单但功能齐全且非常高效
看看 [其他人如何评价 Iris](https://iris-go.com/testimonials/),同时欢迎各位点亮 **star**
> 新版本 11.2 发布! [散布消息](https://dev.to/kataras/iris-version-11-2-released-22bc).
> 新版本 11.2 发布! [散布消息](https://www.facebook.com/iris.framework/posts/3276606095684693).
## 学习 Iris

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).

View File

@ -284,5 +284,10 @@ func main() {
// Last, do not confuse `ctx.Params()` with `ctx.Values()`.
// Path parameter's values can be retrieved from `ctx.Params()`,
// context's local storage that can be used to communicate between handlers and middleware(s) can be stored to `ctx.Values()`.
//
// When registering different parameter types in the same exact path pattern, the path parameter's name
// should differ e.g.
// /path/{name:string}
// /path/{id:uint}
app.Run(iris.Addr(":8080"))
}