Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"if" inside "loop" #134

Open
marcopeg opened this issue Jun 19, 2019 · 1 comment
Open

"if" inside "loop" #134

marcopeg opened this issue Jun 19, 2019 · 1 comment

Comments

@marcopeg
Copy link

Hello, I'm trying to produce an upstream definition out of a list of possible values:

ENV FALLBACK "50.50.50.50;;51.51.5151;;52.52.52.52"
ENV SEPARATOR ";;"

Here is a working piece of template:

upstream fallback {
        {{ range $index, $value := split .Env.FALLBACK .Env.SEPARATOR }}
            server {{ $value }};
        {{end}}
    }

Which produces:

upstream fallback {
    server 50.50.50.50;
    server 51.51.5151;
    server 52.52.52.52;
}

But I would rather obtain this:

upstream fallback {
    server 50.50.50.50;
    server 51.51.5151 backup;
    server 52.52.52.52 backup;
}

I tried:

upstream fallback {
        {{ range $index, $value := split .Env.FALLBACK .Env.SEPARATOR }}
            {{ if eq $index 0 }}
              server {{ $value }};
            {{ else }}
              server {{ $value }} backup;
            {{ end }}
        {{end}}
    }

but I get parsing errors that I can't understand:

2019/06/19 14:44:13 unable to parse template: template: nginx.conf.tmpl:17: unexpected unrecognized character in action: U+00A0 in command

Any ideas?

@ianroberts
Copy link

U+00A0 is the non-breaking space character - check your template and replace all whitespace with real spaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants