Commit 4be6ae6
authored
hooks: Recursively search embedded fields for methods (#494)
* hooks: Recursively search embedded fields for methods
Follow up to #493 and 840220c
Kong currently supports hooks on embedded fields of a parsed node,
but only at the first level of embedding:
```
type mainCmd struct {
FooOptions
}
type FooOptions struct {
BarOptions
}
func (f *FooOptions) BeforeApply() error {
// this will be called
}
type BarOptions struct {
}
func (b *BarOptions) BeforeApply() error {
// this will not be called
}
```
This change adds support for hooks to be defined
on embedded fields of embedded fields so that the above
example would work as expected.
Per #493, the definition of "embedded" field is adjusted to mean:
- Any anonymous (Go-embedded) field that is exported
- Any non-anonymous field that is tagged with `embed:""`
*Testing*:
Includes a test case for embedding an anonymous field in an `embed:""`
and an `embed:""` field in an anonymous field.
* Use recursion to build up the list of receivers
The 'receivers' parameter helps avoid constant memory allocation
as the backing storage for the slice is reused across recursive calls.1 parent 4e1757c commit 4be6ae6
2 files changed
+60
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
81 | 84 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
95 | 92 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
101 | 107 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
106 | 119 | | |
107 | 120 | | |
| 121 | + | |
| 122 | + | |
108 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
109 | 127 | | |
110 | 128 | | |
111 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2405 | 2405 | | |
2406 | 2406 | | |
2407 | 2407 | | |
| 2408 | + | |
| 2409 | + | |
2408 | 2410 | | |
2409 | 2411 | | |
2410 | 2412 | | |
| |||
2414 | 2416 | | |
2415 | 2417 | | |
2416 | 2418 | | |
| 2419 | + | |
| 2420 | + | |
2417 | 2421 | | |
2418 | 2422 | | |
2419 | 2423 | | |
| |||
2422 | 2426 | | |
2423 | 2427 | | |
2424 | 2428 | | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
2425 | 2438 | | |
2426 | 2439 | | |
2427 | 2440 | | |
| |||
2441 | 2454 | | |
2442 | 2455 | | |
2443 | 2456 | | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
2444 | 2460 | | |
2445 | 2461 | | |
2446 | 2462 | | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
2447 | 2466 | | |
2448 | 2467 | | |
2449 | 2468 | | |
| |||
0 commit comments