Could you help provide an example on map function?

60 views
Skip to first unread message

Richard Yang

unread,
Mar 4, 2019, 8:33:45 PM3/4/19
to confd-users

Hi, folks, I am trying to populate a map like property collection like below (it could be any number of entries in the map):

'https://server1.com', { 'property1': 'value11', 'property2': 'value21' },
'https://server2.com', { 'property1': 'value12', 'property2': 'value22' },
'https://server3.com', { 'property1': 'value13', 'property2': 'value23' },
   .......

As you can see, it is more like a map with the keys being a unique url.
I wonder if I can use template map function. The confD website has this documentation:
Template Functions

Rustin Daniels

unread,
Mar 5, 2019, 5:13:34 AM3/5/19
to confd-users
Hi,

It's been a while since I've last worked with confd, but here's some code that might help solve your issue.

nginx.conf.tmpl

upstream app {
   {{range gets "/app/powerping/abd23/es/conf/*"}}
  {{$data := json .Value}}
server {{$data.Conf.NetworkSettings.IPAddress}}:9200;
  {{end}}
  keepalive 1024;
}

server {
  server_name _;
  location / {
    proxy_pass http://app;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    default_type text/html;
    error_page 404 = /fallback;
  }
}

Cheers,
Rustin

Richard Yang

unread,
Mar 9, 2019, 2:04:41 PM3/9/19
to confd-users
Thanks, Rustin, for your help. I think I figured it out now. I had to learn some golang templating.

Richard
Reply all
Reply to author
Forward
0 new messages