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

Access enviromental variables from the go template engine #97

Closed
StayPirate opened this issue May 4, 2022 · 0 comments · Fixed by #98
Closed

Access enviromental variables from the go template engine #97

StayPirate opened this issue May 4, 2022 · 0 comments · Fixed by #98

Comments

@StayPirate
Copy link
Contributor

StayPirate commented May 4, 2022

It would be nice if would be possible to use ENV variables within the template file. Something like:

Content-Type: multipart/mixed; boundary=21ee3da964c7bf70def62adb9ee1a061747003c026e363e47231258c48f1
From: {{ .Env.TO_EMAIL }}
To: {{.To}}

I'm not a golang developer, but I did some research and I found the following snippet which may help here:

func envToMap() (map[string]string, error) {
  envMap := make(map[string]string)
  var err error

  for _, v := range os.Environ() {
    split_v := strings.SplitN(v, "=", 2)
  }
  return envMap, err
}

There also is another template engine named gomplate that can do that directly from its syntax. Anyway, I guess that switching the golang built-in template engine for a new one (and add a new dependency) is not worthy for such a small request.

@StayPirate StayPirate changed the title Accessing enviromental variables from the go template Access enviromental variables from the go template engine May 4, 2022
skx added a commit that referenced this issue May 4, 2022
This pull-request closes #97, by allowing environmental variables
to be used in the email template:

        To: {{env RECIPIENT}}
        From: {{env SENDER}}
        ...
skx added a commit that referenced this issue May 4, 2022
This pull-request closes #97, by allowing environmental variables
to be used in the email template:

        To: {{env "RECIPIENT"}}
        From: {{env "SENDER"}}
        ...
@skx skx closed this as completed in #98 May 4, 2022
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

Successfully merging a pull request may close this issue.

1 participant