Example Go Template Syntax – Conditional If-Else, env,…
1 min read

Example Go Template Syntax – Conditional If-Else, env,…

This is an example of Go template syntax, what are doing here:

  • Create $domain variable with an empty value.
  • Create $ns variable with a value that comes from NAMESPACE environment variable. So, we need to fill that first to make the logic work. E.g export NAMESPACE=staging.
  • Logic / conditional if-else for checking the equality ( eq ) of $ns.
  • printf function for string concatenation.
{{ $domain := "" }}
{{ $ns := env "NAMESPACE" -}}
{{ if eq $ns "staging" -}}
{{ $domain = printf ".%s.svc.cluster.local:2200" $ns }}
{{ else -}}
{{ $domain = printf ".%s.svc.cluster.local:2200" $ns }}
{{ end }}
Ahmad-Lukman-Hakim

Admin LUKMANLAB, DevOps Engineer, Site Reliability Engineer, System Administrator.

Berita Olahraga

Anime Batch

News

Pelajaran Sekolah

Berita Terkini

Berita Terkini

Jadwal pertadingan malam ini