From 27a8625ccde346a659c6df56bf44ae5065e0e3c7 Mon Sep 17 00:00:00 2001 From: Igor Artasevych Date: Thu, 8 Oct 2020 18:38:59 +0300 Subject: [PATCH 1/2] #1193 Expose constructor of MapInputSource type --- altsrc/map_input_source.go | 5 +++++ altsrc/map_input_source_test.go | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/altsrc/map_input_source.go b/altsrc/map_input_source.go index 661b7856d4..b144cf64c0 100644 --- a/altsrc/map_input_source.go +++ b/altsrc/map_input_source.go @@ -16,6 +16,11 @@ type MapInputSource struct { valueMap map[interface{}]interface{} } +//NewMapInputSource create a new MapInputSource type +func NewMapInputSource(file string, valueMap map[interface{}]interface{}) *MapInputSource { + return &MapInputSource{file: file, valueMap: valueMap} +} + // nestedVal checks if the name has '.' delimiters. // If so, it tries to traverse the tree by the '.' delimited sections to find // a nested value for the key. diff --git a/altsrc/map_input_source_test.go b/altsrc/map_input_source_test.go index 5046d1485d..b90f796b30 100644 --- a/altsrc/map_input_source_test.go +++ b/altsrc/map_input_source_test.go @@ -6,14 +6,13 @@ import ( ) func TestMapDuration(t *testing.T) { - inputSource := &MapInputSource{ - file: "test", - valueMap: map[interface{}]interface{}{ + inputSource := NewMapInputSource( + "test", + map[interface{}]interface{}{ "duration_of_duration_type": time.Minute, "duration_of_string_type": "1m", "duration_of_int_type": 1000, - }, - } + }) d, err := inputSource.Duration("duration_of_duration_type") expect(t, time.Minute, d) expect(t, nil, err) From 7f005015c80472e56697d0e8b5abf9b59f9f0731 Mon Sep 17 00:00:00 2001 From: Igor Artasevych Date: Thu, 22 Oct 2020 10:00:45 +0300 Subject: [PATCH 2/2] Update altsrc/map_input_source.go Co-authored-by: Robert Liebowitz --- altsrc/map_input_source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/altsrc/map_input_source.go b/altsrc/map_input_source.go index b144cf64c0..117461f5a0 100644 --- a/altsrc/map_input_source.go +++ b/altsrc/map_input_source.go @@ -16,7 +16,7 @@ type MapInputSource struct { valueMap map[interface{}]interface{} } -//NewMapInputSource create a new MapInputSource type +// NewMapInputSource creates a new MapInputSource for implementing custom input sources. func NewMapInputSource(file string, valueMap map[interface{}]interface{}) *MapInputSource { return &MapInputSource{file: file, valueMap: valueMap} }