Skip to content

A way to set envconfig variables when the value is longer than 1024 bytes

License

Notifications You must be signed in to change notification settings

marzagao/envconfigfromfile

Repository files navigation

envconfigfromfile

Build Status codecov

My colleague @adammck found that:

long environment variables can be stored in /etc/environment, but pam_env (which is responsible for loading those into the shell when a user logs) has a bug which causes it to truncate lines longer than 1024 bytes.

So to simplify the loading of environment variables longer than 1024 bytes using the convenient envconfig tagging, I created this library to set a configuration variable using the contents of a file. The value of the environment variable named in the envconfig tag should be the path of the file to be read from.

Example:

Given that:

  • The TEST_FIELD_FILE_PATH environment variable has the value "contents.txt"
  • The file contents.txt contains the text some-content

The following program:

package main

import (
  "fmt"

  "github.com/kelseyhightower/envconfig"
  "github.com/marzagao/envconfigfromfile"
)

type TestStruct struct {
  TestField *envconfigfromfile.EnvConfigFromFile `envconfig:"TEST_FIELD_FILE_PATH"`
}

func main() {
  testStruct := TestStruct{}
  envconfig.Process("", &testStruct)
  fmt.Println(testStruct.TestField.String())
}

Will output some-content.

About

A way to set envconfig variables when the value is longer than 1024 bytes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published