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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user