diff --git a/README.md b/README.md index 71a6efbd..033c3c4f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # News -> This is the under-development branch. Stay tuned for the upcoming release [v12.2.0](HISTORY.md#Next). +> This is the under-**development branch**. Stay tuned for the upcoming release [v12.2.0](HISTORY.md#Next). Looking for a stable release? Head over to the [v12.1.8 branch](https://github.com/kataras/iris/tree/v12.1.8) instead. @@ -22,7 +22,7 @@ Learn what [others saying about Iris](https://iris-go.com/testimonials/) and **[ [![](https://media.giphy.com/media/j5WLmtvwn98VPrm7li/giphy.gif)](https://iris-go.com/testimonials/) -[![Benchmarks: Apr 2, 2020 at 12:13pm (UTC)](https://iris-go.com/images/benchmarks.svg)](https://github.com/kataras/server-benchmarks) +[![Benchmarks: Jul 18, 2020 at 10:46am (UTC)](https://iris-go.com/images/benchmarks.svg)](https://github.com/kataras/server-benchmarks) ## 📖 Learning Iris diff --git a/_examples/apidoc/yaag/go.mod b/_examples/apidoc/yaag/go.mod index b38a8e79..84abcc14 100644 --- a/_examples/apidoc/yaag/go.mod +++ b/_examples/apidoc/yaag/go.mod @@ -4,5 +4,5 @@ go 1.14 require ( github.com/betacraft/yaag v1.0.1-0.20191027021412-565f65e36090 - github.com/kataras/iris/v12 v12.1.9-0.20200710202109-5d80ecac5371 + github.com/kataras/iris/v12 v12.1.9-0.20200718094131-5228aa163dc9 ) diff --git a/_examples/database/mongodb/go.mod b/_examples/database/mongodb/go.mod index d75e6fe7..3170e592 100644 --- a/_examples/database/mongodb/go.mod +++ b/_examples/database/mongodb/go.mod @@ -4,6 +4,6 @@ go 1.14 require ( github.com/joho/godotenv v1.3.0 - github.com/kataras/iris/v12 v12.1.9-0.20200710202109-5d80ecac5371 + github.com/kataras/iris/v12 v12.1.9-0.20200718094131-5228aa163dc9 go.mongodb.org/mongo-driver v1.3.4 ) diff --git a/_examples/database/mysql/go.mod b/_examples/database/mysql/go.mod index 4e7f1a55..56e7e1dd 100644 --- a/_examples/database/mysql/go.mod +++ b/_examples/database/mysql/go.mod @@ -4,6 +4,6 @@ go 1.14 require ( github.com/go-sql-driver/mysql v1.5.0 - github.com/kataras/iris/v12 v12.1.9-0.20200710202109-5d80ecac5371 + github.com/kataras/iris/v12 v12.1.9-0.20200718094131-5228aa163dc9 github.com/mailgun/groupcache/v2 v2.1.0 ) diff --git a/_examples/kafka-api/go.mod b/_examples/kafka-api/go.mod index 662641fc..73f9fdcb 100644 --- a/_examples/kafka-api/go.mod +++ b/_examples/kafka-api/go.mod @@ -4,5 +4,5 @@ go 1.14 require ( github.com/Shopify/sarama v1.26.4 - github.com/kataras/iris/v12 v12.1.9-0.20200710202109-5d80ecac5371 + github.com/kataras/iris/v12 v12.1.9-0.20200718094131-5228aa163dc9 ) diff --git a/_examples/mvc/overview/go.mod b/_examples/mvc/overview/go.mod index 293e15d1..9878da6b 100644 --- a/_examples/mvc/overview/go.mod +++ b/_examples/mvc/overview/go.mod @@ -2,4 +2,4 @@ module app go 1.14 -require github.com/kataras/iris/v12 v12.1.9-0.20200710202109-5d80ecac5371 +require github.com/kataras/iris/v12 v12.1.9-0.20200718094131-5228aa163dc9 diff --git a/_examples/routing/basic/main.go b/_examples/routing/basic/main.go index 7300217a..1ba67a82 100644 --- a/_examples/routing/basic/main.go +++ b/_examples/routing/basic/main.go @@ -146,7 +146,7 @@ func newApp() *iris.Application { }) // http://v1.localhost:8080/api/users/42 usersAPI.Get("/{userid:int}", func(ctx iris.Context) { - ctx.Writef("user with id: %s", ctx.Params().Get("userid")) + ctx.Writef("user with id: %d", ctx.Params().GetIntDefault("userid", 0)) }) } } diff --git a/_examples/websocket/socketio/go.mod b/_examples/websocket/socketio/go.mod index cb53249d..0c18fed9 100644 --- a/_examples/websocket/socketio/go.mod +++ b/_examples/websocket/socketio/go.mod @@ -4,5 +4,5 @@ go 1.14 require ( github.com/googollee/go-socket.io v1.4.3-0.20191109153049-7451e2f8c2e0 - github.com/kataras/iris/v12 v12.1.9-0.20200710202109-5d80ecac5371 + github.com/kataras/iris/v12 v12.1.9-0.20200718094131-5228aa163dc9 ) diff --git a/context/request_params.go b/context/request_params.go index 3f7efd71..4aa4ae78 100644 --- a/context/request_params.go +++ b/context/request_params.go @@ -16,11 +16,36 @@ type RequestParams struct { memstore.Store } -// Set inserts a value to the key-value storage. -// -// See `SetImmutable` and `Get` too. +// Set inserts a parameter value. +// See `Get` too. func (r *RequestParams) Set(key, value string) { - r.Store.Set(key, value) + if ln := len(r.Store); cap(r.Store) > ln { + r.Store = r.Store[:ln+1] + p := &r.Store[ln] + p.Key = key + p.ValueRaw = value + return + } + + r.Store = append(r.Store, memstore.Entry{ + Key: key, + ValueRaw: value, + }) +} + +// Get returns a path parameter's value based on its route's dynamic path key. +func (r *RequestParams) Get(key string) string { + for i := 0; i < len(r.Store); i++ { + if kv := r.Store[i]; kv.Key == key { + if v, ok := kv.ValueRaw.(string); ok { + return v // it should always be string here on :string parameter. + } + + return fmt.Sprintf("%s", kv.ValueRaw) + } + } + + return "" } // GetEntryAt will return the parameter's internal store's `Entry` based on the index. @@ -45,24 +70,19 @@ func (r *RequestParams) Visit(visitor func(key string, value string)) { }) } -// Get returns a path parameter's value based on its route's dynamic path key. -func (r RequestParams) Get(key string) string { - return r.GetString(key) -} - // GetTrim returns a path parameter's value without trailing spaces based on its route's dynamic path key. -func (r RequestParams) GetTrim(key string) string { +func (r *RequestParams) GetTrim(key string) string { return strings.TrimSpace(r.Get(key)) } // GetEscape returns a path parameter's double-url-query-escaped value based on its route's dynamic path key. -func (r RequestParams) GetEscape(key string) string { +func (r *RequestParams) GetEscape(key string) string { return DecodeQuery(DecodeQuery(r.Get(key))) } // GetDecoded returns a path parameter's double-url-query-escaped value based on its route's dynamic path key. // same as `GetEscape`. -func (r RequestParams) GetDecoded(key string) string { +func (r *RequestParams) GetDecoded(key string) string { return r.GetEscape(key) } @@ -70,7 +90,7 @@ func (r RequestParams) GetDecoded(key string) string { // Usage: Get an id from a wildcard path. // // Returns -1 and false if not path parameter with that "key" found. -func (r RequestParams) GetIntUnslashed(key string) (int, bool) { +func (r *RequestParams) GetIntUnslashed(key string) (int, bool) { v := r.Get(key) if v != "" { if len(v) > 1 {