MCPcopy
hub / github.com/hashicorp/hcl / decodeBlockToValue

Function decodeBlockToValue

gohcl/decode.go:276–300  ·  view source on GitHub ↗
(block *hcl.Block, ctx *hcl.EvalContext, v reflect.Value)

Source from the content-addressed store, hash-verified

274}
275
276func decodeBlockToValue(block *hcl.Block, ctx *hcl.EvalContext, v reflect.Value) hcl.Diagnostics {
277 diags := decodeBodyToValue(block.Body, ctx, v)
278
279 blockTags := getFieldTags(v.Type())
280 for li, lv := range block.Labels {
281 lfieldIdx := blockTags.Labels[li].FieldIndex
282 lfieldName := blockTags.Labels[li].Name
283
284 v.Field(lfieldIdx).Set(reflect.ValueOf(lv))
285
286 if ix, exists := blockTags.LabelRange[lfieldName]; exists {
287 v.Field(ix).Set(reflect.ValueOf(block.LabelRanges[li]))
288 }
289 }
290
291 if blockTags.TypeRange != nil {
292 v.Field(*blockTags.TypeRange).Set(reflect.ValueOf(block.TypeRange))
293 }
294
295 if blockTags.DefRange != nil {
296 v.Field(*blockTags.DefRange).Set(reflect.ValueOf(block.DefRange))
297 }
298
299 return diags
300}
301
302// DecodeExpression extracts the value of the given expression into the given
303// value. This value must be something that gocty is able to decode into,

Callers 1

decodeBodyToStructFunction · 0.85

Calls 4

decodeBodyToValueFunction · 0.85
getFieldTagsFunction · 0.85
SetMethod · 0.80
TypeMethod · 0.45

Tested by

no test coverage detected