From 916b94eb3aac698918e79a7b8592ac0ce5b74012 Mon Sep 17 00:00:00 2001 From: Andrii Soldatenko Date: Sun, 16 Jul 2023 21:00:18 +0200 Subject: [PATCH] Added support for configuring array values with environment variables #3511 Signed-off-by: Andrii Soldatenko --- configuration/parser.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/configuration/parser.go b/configuration/parser.go index 6d645180..017d63a9 100644 --- a/configuration/parser.go +++ b/configuration/parser.go @@ -166,6 +166,17 @@ func (p *Parser) overwriteFields(v reflect.Value, fullpath string, path []string return p.overwriteStruct(v, fullpath, path, payload) case reflect.Map: return p.overwriteMap(v, fullpath, path, payload) + case reflect.Slice: + idx, err := strconv.Atoi(path[0]) + if err != nil { + panic("non-numeric index: " + path[0]) + } + + if idx >= v.Len() { + panic("Undefined index: " + path[0]) + } + + return p.overwriteFields(v.Index(idx), fullpath, path[1:], payload) case reflect.Interface: if v.NumMethod() == 0 { if !v.IsNil() {