mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 08:26:26 +01:00
README: update benchmarks.
minor performance boost by making RequestParameter Set and Get methods more direct to the underline Memstore's kv Former-commit-id: 4fae45b5bd23804e88aac1f7c66055dd81efc9c9
This commit is contained in:
parent
fb8e677c08
commit
a1991a0830
|
@ -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.
|
||||
|
||||
<!--  Iris version **12.1.8** has been [released](HISTORY.md#su-16-february-2020--v1218)! -->
|
||||
|
||||
|
@ -22,7 +22,7 @@ Learn what [others saying about Iris](https://iris-go.com/testimonials/) and **[
|
|||
|
||||
[](https://iris-go.com/testimonials/)
|
||||
|
||||
[](https://github.com/kataras/server-benchmarks)
|
||||
[](https://github.com/kataras/server-benchmarks)
|
||||
|
||||
## 📖 Learning Iris
|
||||
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user