@@ -27,6 +27,10 @@ import (
27
27
// The function will panic if given a non-pointer as the Go value target,
28
28
// since that is considered to be a bug in the calling program.
29
29
func FromCtyValue (val cty.Value , target interface {}) error {
30
+ return FromCtyValueTagged (val , target , "cty" )
31
+ }
32
+
33
+ func FromCtyValueTagged (val cty.Value , target interface {}, tag string ) error {
30
34
tVal := reflect .ValueOf (target )
31
35
if tVal .Kind () != reflect .Ptr {
32
36
panic ("target value is not a pointer" )
@@ -40,10 +44,10 @@ func FromCtyValue(val cty.Value, target interface{}) error {
40
44
// unused capacity on the end of it, depending on how deeply-recursive
41
45
// the given cty.Value is.
42
46
path := make (cty.Path , 0 )
43
- return fromCtyValue (val , tVal , path )
47
+ return fromCtyValue (val , tVal , path , tag )
44
48
}
45
49
46
- func fromCtyValue (val cty.Value , target reflect.Value , path cty.Path ) error {
50
+ func fromCtyValue (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
47
51
ty := val .Type ()
48
52
49
53
deepTarget := fromCtyPopulatePtr (target , false )
@@ -89,17 +93,17 @@ func fromCtyValue(val cty.Value, target reflect.Value, path cty.Path) error {
89
93
90
94
switch {
91
95
case ty .IsListType ():
92
- return fromCtyList (val , target , path )
96
+ return fromCtyList (val , target , path , tag )
93
97
case ty .IsMapType ():
94
- return fromCtyMap (val , target , path )
98
+ return fromCtyMap (val , target , path , tag )
95
99
case ty .IsSetType ():
96
- return fromCtySet (val , target , path )
100
+ return fromCtySet (val , target , path , tag )
97
101
case ty .IsObjectType ():
98
- return fromCtyObject (val , target , path )
102
+ return fromCtyObject (val , target , path , tag )
99
103
case ty .IsTupleType ():
100
- return fromCtyTuple (val , target , path )
104
+ return fromCtyTuple (val , target , path , tag )
101
105
case ty .IsCapsuleType ():
102
- return fromCtyCapsule (val , target , path )
106
+ return fromCtyCapsule (val , target , path , tag )
103
107
}
104
108
105
109
// We should never fall out here; reaching here indicates a bug in this
@@ -251,7 +255,7 @@ func fromCtyString(val cty.Value, target reflect.Value, path cty.Path) error {
251
255
}
252
256
}
253
257
254
- func fromCtyList (val cty.Value , target reflect.Value , path cty.Path ) error {
258
+ func fromCtyList (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
255
259
switch target .Kind () {
256
260
257
261
case reflect .Slice :
@@ -273,7 +277,7 @@ func fromCtyList(val cty.Value, target reflect.Value, path cty.Path) error {
273
277
}
274
278
275
279
targetElem := tv .Index (i )
276
- err = fromCtyValue (val , targetElem , path )
280
+ err = fromCtyValue (val , targetElem , path , tag )
277
281
if err != nil {
278
282
return true
279
283
}
@@ -310,7 +314,7 @@ func fromCtyList(val cty.Value, target reflect.Value, path cty.Path) error {
310
314
}
311
315
312
316
targetElem := target .Index (i )
313
- err = fromCtyValue (val , targetElem , path )
317
+ err = fromCtyValue (val , targetElem , path , tag )
314
318
if err != nil {
315
319
return true
316
320
}
@@ -332,7 +336,7 @@ func fromCtyList(val cty.Value, target reflect.Value, path cty.Path) error {
332
336
}
333
337
}
334
338
335
- func fromCtyMap (val cty.Value , target reflect.Value , path cty.Path ) error {
339
+ func fromCtyMap (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
336
340
337
341
switch target .Kind () {
338
342
@@ -356,7 +360,7 @@ func fromCtyMap(val cty.Value, target reflect.Value, path cty.Path) error {
356
360
ks := key .AsString ()
357
361
358
362
targetElem := reflect .New (et )
359
- err = fromCtyValue (val , targetElem , path )
363
+ err = fromCtyValue (val , targetElem , path , tag )
360
364
361
365
tv .SetMapIndex (reflect .ValueOf (ks ), targetElem .Elem ())
362
366
@@ -377,7 +381,7 @@ func fromCtyMap(val cty.Value, target reflect.Value, path cty.Path) error {
377
381
}
378
382
}
379
383
380
- func fromCtySet (val cty.Value , target reflect.Value , path cty.Path ) error {
384
+ func fromCtySet (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
381
385
switch target .Kind () {
382
386
383
387
case reflect .Slice :
@@ -393,7 +397,7 @@ func fromCtySet(val cty.Value, target reflect.Value, path cty.Path) error {
393
397
var err error
394
398
val .ForEachElement (func (key cty.Value , val cty.Value ) bool {
395
399
targetElem := tv .Index (i )
396
- err = fromCtyValue (val , targetElem , path )
400
+ err = fromCtyValue (val , targetElem , path , tag )
397
401
if err != nil {
398
402
return true
399
403
}
@@ -422,7 +426,7 @@ func fromCtySet(val cty.Value, target reflect.Value, path cty.Path) error {
422
426
var err error
423
427
val .ForEachElement (func (key cty.Value , val cty.Value ) bool {
424
428
targetElem := target .Index (i )
425
- err = fromCtyValue (val , targetElem , path )
429
+ err = fromCtyValue (val , targetElem , path , tag )
426
430
if err != nil {
427
431
return true
428
432
}
@@ -444,14 +448,14 @@ func fromCtySet(val cty.Value, target reflect.Value, path cty.Path) error {
444
448
}
445
449
}
446
450
447
- func fromCtyObject (val cty.Value , target reflect.Value , path cty.Path ) error {
451
+ func fromCtyObject (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
448
452
449
453
switch target .Kind () {
450
454
451
455
case reflect .Struct :
452
456
453
457
attrTypes := val .Type ().AttributeTypes ()
454
- targetFields := structTagIndices (target .Type ())
458
+ targetFields := structTagIndices (target .Type (), tag )
455
459
456
460
path = append (path , nil )
457
461
@@ -482,7 +486,7 @@ func fromCtyObject(val cty.Value, target reflect.Value, path cty.Path) error {
482
486
ev := val .GetAttr (k )
483
487
484
488
targetField := target .Field (fieldIdx )
485
- err := fromCtyValue (ev , targetField , path )
489
+ err := fromCtyValue (ev , targetField , path , tag )
486
490
if err != nil {
487
491
return err
488
492
}
@@ -498,7 +502,7 @@ func fromCtyObject(val cty.Value, target reflect.Value, path cty.Path) error {
498
502
}
499
503
}
500
504
501
- func fromCtyTuple (val cty.Value , target reflect.Value , path cty.Path ) error {
505
+ func fromCtyTuple (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
502
506
503
507
switch target .Kind () {
504
508
@@ -521,7 +525,7 @@ func fromCtyTuple(val cty.Value, target reflect.Value, path cty.Path) error {
521
525
ev := val .Index (cty .NumberIntVal (int64 (i )))
522
526
523
527
targetField := target .Field (i )
524
- err := fromCtyValue (ev , targetField , path )
528
+ err := fromCtyValue (ev , targetField , path , tag )
525
529
if err != nil {
526
530
return err
527
531
}
@@ -537,7 +541,7 @@ func fromCtyTuple(val cty.Value, target reflect.Value, path cty.Path) error {
537
541
}
538
542
}
539
543
540
- func fromCtyCapsule (val cty.Value , target reflect.Value , path cty.Path ) error {
544
+ func fromCtyCapsule (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
541
545
542
546
if target .Kind () == reflect .Ptr {
543
547
// Walk through indirection until we get to the last pointer,
0 commit comments