File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,27 @@ import (
1010 "github.com/expr-lang/expr/internal/deref"
1111)
1212
13+ // Proxy is an interface that allows intercepting object property read and write operations.
14+ type Proxy interface {
15+ ProxyGetter
16+ }
17+
18+ // ProxyGetter is an interface that allows intercepting object property access.
19+ type ProxyGetter interface {
20+ // GetProperty returns the value of the property with the given key.
21+ GetProperty (key string ) (any , bool )
22+ }
23+
1324func Fetch (from , i any ) any {
25+ if proxy , ok := from .(ProxyGetter ); ok {
26+ r , ok := proxy .GetProperty (i .(string ))
27+ if ! ok {
28+ panic (fmt .Sprintf ("cannot fetch %v from %T" , i , from ))
29+ }
30+
31+ return r
32+ }
33+
1434 v := reflect .ValueOf (from )
1535 if v .Kind () == reflect .Invalid {
1636 panic (fmt .Sprintf ("cannot fetch %v from %T" , i , from ))
You can’t perform that action at this time.
0 commit comments