英文:
Go: Using environment variables in if statement in Template
问题
以下是我用于NGINX配置的Go模板代码。在嵌套的if语句中,我试图检查环境变量IS_CUSTOMER的值是否等于"true"。
{{ if eq .instanceName "apple" }}
{{ if eq ({{envOrKey "IS_CUSTOMER"}}) "true" }}
listen 127.0.0.1:{{.port}};
{{else}}
listen {{.bindAddress}}:{{.port}};
{{end}}
{{else}}
listen {{.bindAddress}}:{{.port}};
{{end}}
listen 443 ssl;
但是当我执行模板时,出现以下错误:
tenanttemplate.tmpl:13: unexpected "{" in operand
我查阅了Go模板的在线文档和一些Stack Overflow上的答案,但没有帮助。
英文:
Below is a Go template code that I am using for NGINX configuration. In the nested if statement, I am trying to check if the value of the environment variable IS_CUSTOMER is equal to "true".
{{ if eq .instanceName "apple" }}
{{ if eq ({{envOrKey "IS_CUSTOMER"}}) "true" }}
listen 127.0.0.1:{{.port}};
{{else}}
listen {{.bindAddress}}:{{.port}};
{{end}}
{{else}}
listen {{.bindAddress}}:{{.port}};
{{end}}
listen 443 ssl ;
But when I execute the template, I am getting the following error:
tenanttemplate.tmpl:13: unexpected \"{\" in operand"
I went through online documentation of Go template and some other answers on Stack overflow, it didn't help.
答案1
得分: 3
将以下内容翻译为中文:
将
{{ if eq ({{envOrKey "IS_CUSTOMER"}}) "true" }}
改为
{{ if eq (envOrKey "IS_CUSTOMER") "true" }}
英文:
Change
{{ if eq ({{envOrKey "IS_CUSTOMER"}}) "true" }}
to
{{ if eq (envOrKey "IS_CUSTOMER") "true" }}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论