Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Access enviromental variables from the go template engine #97

@StayPirate

Description

@StayPirate

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions