Fixup expr variable lookup, simplified traversal step access
@@ -24,12 +24,16 @@ func MustBuffer(ctxBodies []hcl.Body) BufferOption {
}
for _, attr := range attrs {
for _, traversal := range attr.Expr.Variables() {
+ if len(traversal) < 2 {
+ continue
+ }
+
rootName := traversal.RootName()
if rootName != ClientRequest && rootName != BackendResponse {
continue
}
- for _, step := range traversal[1:] {
- nameField := reflect.ValueOf(step).FieldByName("Name")
+
+ nameField := reflect.ValueOf(traversal[1]).FieldByName("Name")
name := nameField.String()
switch name {
case JsonBody:
@@ -47,6 +51,5 @@ func MustBuffer(ctxBodies []hcl.Body) BufferOption {
}
}
}
- }
return result
}
