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

fix https://github.com/kataras/iris/issues/1450 and continue on implementing 1449

Former-commit-id: 617f64d061e88f050a443ea1751fa244164656c5
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-02-14 23:34:56 +02:00
parent 09a410c6cb
commit c13fd84354
24 changed files with 581 additions and 144 deletions

View File

@@ -16,6 +16,7 @@ import (
"os"
"path"
"path/filepath"
"reflect"
"regexp"
"strconv"
"strings"
@@ -994,6 +995,10 @@ type Context interface {
// It will search from the current subdomain of context's host, if not inside the root domain.
RouteExists(method, path string) bool
// ReflectValue caches and returns a []reflect.Value{reflect.ValueOf(ctx)}.
// It's just a helper to maintain variable inside the context itself.
ReflectValue() []reflect.Value
// Application returns the iris app instance which belongs to this context.
// Worth to notice that this function returns an interface
// of the Application, which contains methods that are safe
@@ -4608,6 +4613,22 @@ func (ctx *context) RouteExists(method, path string) bool {
return ctx.Application().RouteExists(ctx, method, path)
}
const (
reflectValueContextKey = "_iris_context_reflect_value"
)
// ReflectValue caches and returns a []reflect.Value{reflect.ValueOf(ctx)}.
// It's just a helper to maintain variable inside the context itself.
func (ctx *context) ReflectValue() []reflect.Value {
if v := ctx.Values().Get(reflectValueContextKey); v != nil {
return v.([]reflect.Value)
}
v := []reflect.Value{reflect.ValueOf(ctx)}
ctx.Values().Set(reflectValueContextKey, v)
return v
}
// Application returns the iris app instance which belongs to this context.
// Worth to notice that this function returns an interface
// of the Application, which contains methods that are safe