Skip to content

Commit a72a347

Browse files
committed
Fix reflection of struct ptr slices
Required for the agent config
1 parent 1f79649 commit a72a347

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tools/doc-generator/parse/parser.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,17 @@ func config(block *ConfigBlock, cfg interface{}, flags map[uintptr]*flag.Flag, r
132132
}
133133

134134
// The input config is expected to be addressable.
135-
if reflect.TypeOf(cfg).Kind() != reflect.Ptr {
136-
t := reflect.TypeOf(cfg)
137-
return nil, fmt.Errorf("%s is a %s while a %s is expected", t, t.Kind(), reflect.Ptr)
135+
v := reflect.ValueOf(cfg)
136+
for v.Kind() != reflect.Struct {
137+
// if pointer is zero recreate object
138+
if v.IsZero() {
139+
v = reflect.New(reflect.TypeOf(v))
140+
}
141+
// The input config is expected to be a pointer to struct.
142+
v = v.Elem()
138143
}
139144

140-
// The input config is expected to be a pointer to struct.
141-
v := reflect.ValueOf(cfg).Elem()
142145
t := v.Type()
143-
144146
if v.Kind() != reflect.Struct {
145147
return nil, fmt.Errorf("%s is a %s while a %s is expected", v, v.Kind(), reflect.Struct)
146148
}

0 commit comments

Comments
 (0)