sprig icon indicating copy to clipboard operation
sprig copied to clipboard

Change return types of "split" and "splitn" to map[string]interface{} (instead of map[string]string)

Open rpasche opened this issue 1 year ago • 3 comments

Hi,

I just noticed, that I cannot use hasKey function on a dict created by the split or splitn functions, as they both return dicts of type map[string]string whereas most of the functions in dict.go expect a dict of type map[string]interface{}

{{- $mysplit := splitn "$" 2 "foo" }}
{{- if hasKey $mysplit "_1" }}
  2nd_part: {{ $mysplit._1 }}
{{- end }}

The error I get is

Error: template: .... at <$mysplit>: wrong type for value; expected map[string]interface {}; got map[string]string

Basically, the same error when trying to use get function

{{- $mysplit := splitn "$" 2 "foo" }}
1st_part: {{ get $mysplit. "_0" }}

The error I get is

Error: template: .... at <$mysplit>: wrong type for value; expected map[string]interface {}; got map[string]string

rpasche avatar Apr 30 '24 10:04 rpasche

@rpasche Did you ever find out how to fix this?

DanteMichaeli avatar Oct 01 '24 09:10 DanteMichaeli

Sadly no. Only iterating via range and checking, if the key matches the desired string worked for me

rpasche avatar Oct 02 '24 10:10 rpasche

right.. I created a specific function converting the map[string]string to a map[string]interface{} type. Thanks for the answer!

DanteMichaeli avatar Oct 02 '24 11:10 DanteMichaeli