@@ -374,6 +374,10 @@ func setConfig(prefix string, vip *viper.Viper, target interface{}) {
374
374
val = val .Elem ()
375
375
typ = val .Type ()
376
376
}
377
+
378
+ // Manually bind to env to support CODER_$INDEX_$FIELD format for structured slices.
379
+ _ = vip .BindEnv (prefix , formatEnv (prefix ))
380
+
377
381
if strings .HasPrefix (typ .Name (), "DeploymentConfigField[" ) {
378
382
value := val .FieldByName ("Value" ).Interface ()
379
383
switch value .(type ) {
@@ -421,8 +425,7 @@ func setConfig(prefix string, vip *viper.Viper, target interface{}) {
421
425
case reflect .Slice :
422
426
for j := 0 ; j < fv .Len (); j ++ {
423
427
key := fmt .Sprintf ("%s.%d" , key , j )
424
- v := fv .Index (j )
425
- setConfig (key , vip , v )
428
+ setConfig (key , vip , fv .Index (j ).Interface ())
426
429
}
427
430
default :
428
431
panic (fmt .Sprintf ("unsupported type %T" , ft ))
@@ -466,10 +469,8 @@ func setViperDefaults(prefix string, vip *viper.Viper, target interface{}) {
466
469
case reflect .Ptr :
467
470
setViperDefaults (key , vip , fv .Interface ())
468
471
case reflect .Slice :
469
- for j := 0 ; j < fv .Len (); j ++ {
470
- key := fmt .Sprintf ("%s.%d" , key , j )
471
- setViperDefaults (key , vip , fv .Index (j ))
472
- }
472
+ // we currently don't support default values on structured slices
473
+ continue
473
474
default :
474
475
panic (fmt .Sprintf ("unsupported type %T" , ft ))
475
476
}
@@ -539,7 +540,7 @@ func setFlags(prefix string, flagset *pflag.FlagSet, vip *viper.Viper, target in
539
540
case reflect .Slice :
540
541
for j := 0 ; j < fv .Len (); j ++ {
541
542
key := fmt .Sprintf ("%s.%d" , key , j )
542
- setFlags (key , flagset , vip , fv .Index (j ), enterprise )
543
+ setFlags (key , flagset , vip , fv .Index (j ). Interface () , enterprise )
543
544
}
544
545
default :
545
546
panic (fmt .Sprintf ("unsupported type %T" , ft ))
0 commit comments