# \[SOLVED\] Need help fixing loop in template

**URL:** <https://forum.golangbridge.org/t/solved-need-help-fixing-loop-in-template/16643>\
**Category:** Getting Help\
**Created:** [December 13, 2019, 3:36am UTC](https://forum.golangbridge.org/t/solved-need-help-fixing-loop-in-template/16643 "2019-12-13T03:36:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_V](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/eric_v/32/6403_2.png) [@Eric\_V](https://forum.golangbridge.org/u/Eric_V)\
**Post date:** [December 13, 2019, 3:36am UTC](https://forum.golangbridge.org/t/solved-need-help-fixing-loop-in-template/16643/1 "2019-12-13T03:36:39Z")

</div>

Hi,  
I’m a beginner in Go and am struggling with the different types. This is for a Helm template.  
In my values.yaml file I have this structure for my variables:

```auto
receivers:
  opencensus:
    port: 55678
  zipkin:
    port: 9411
  jaeger:
    jaeger-thrift-tchannel-port: 14267
    jaeger-thrift-http-port: 14268
exporters:
  stackdriver:
    project: "vigilant-sol-256207"
    enable_tracing: true

```

My end result needs to be this:

```auto
data:
  oc-collector-config: |
    receivers:
      opencensus:
        port: 55678
      zipkin:
        port: 9411
      jaeger:
        jaeger-thrift-tchannel-port: 14267
        jaeger-thrift-http-port: 14268
    exporters:
      stackdriver:
        project: "vigilant-sol-256207"
        enable_tracing: true

```

This is about the closest I got:

```auto
  oc-collector-config: |
    receivers:
  {{- range $i, $receivers := .Values.receivers }}
  {{ $receivers | indent 6 }}
  {{ end }}
    exporters:
  {{- range $i, $exporters := .Values.exporters }}
  {{ $exporters | indent 6 }}
  {{ end }}

```

but it throws me the following error:  
`at <6>: wrong type for value; expected string; got map[string]interface {}`  
Can someone please explain me what I’m doing wrong here? I’ve been struggling with it for hours now.

Any help is greatly appreciated.

Kind regards,

Eric V.

---

<div class="post-metadata">

**Author:** ![Eric\_V](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/eric_v/32/6403_2.png) [@Eric\_V](https://forum.golangbridge.org/u/Eric_V)\
**Post date:** [December 16, 2019, 4:58am UTC](https://forum.golangbridge.org/t/solved-need-help-fixing-loop-in-template/16643/2 "2019-12-16T04:58:36Z")

</div>

OK, got one step closer…  
Using the same input and this in my template:

```auto
  {{- range $k, $v := .Values.receivers }}
    {{ $k | indent 2 }}: {{ $v }}
  {{ end }}

```

The result is now:

```auto
receivers:
    jaeger: map[jaeger_thrift_http_port:14268 jaeger_thrift_tchannel_port:14267]
    opencensus: map[port:55678] 
    zipkin: map[port:9411]

```

But I’m struggling to get that last map handled.  
Anybody that can help me out please?

Kind regards,

Eric V.

---

<div class="post-metadata">

**Author:** ![Eric\_V](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/eric_v/32/6403_2.png) [@Eric\_V](https://forum.golangbridge.org/u/Eric_V)\
**Post date:** [December 16, 2019, 5:14am UTC](https://forum.golangbridge.org/t/solved-need-help-fixing-loop-in-template/16643/3 "2019-12-16T05:14:47Z")

</div>

Got it!  
This one finally works:

```auto
  {{- range $k, $v := .Values.receivers }}
    {{ $k | indent 2 }}:
      {{- range $k2, $v2 := $v }}
        {{ $k2 }}: {{ $v2 }}
    {{- end }}
  {{- end }}

```

Kind regards,

Eric V.

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [March 15, 2020, 5:14am UTC](https://forum.golangbridge.org/t/solved-need-help-fixing-loop-in-template/16643/4 "2020-03-15T05:14:52Z")

</div>

Closed on March 15, 2020, 5:14am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
