Documentation
¶
Overview ¶
Package envfile provides tools to read and load environment variables from files.
Index ¶
- func Generate(filename string, v any, fmt env.Formatter) error
- func Load(filename string) error
- func LoadFS(fsys fs.FS, filename string) error
- func Overload(filename string) error
- func OverloadFS(fsys fs.FS, filename string) error
- func Write(filename string, v any) (err error)
- type Encoder
- type Reader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶ added in v0.4.4
Generate encodes and writes the env file at the provided filename. It is meant to be used with "go generate" to create .env files based on the project's config(s).
func Overload ¶
Overload reads from filename and sets and overwrites the environment variables using env.Overload.
func OverloadFS ¶
OverloadFS reads from filename and sets and overwrites the environment variables using env.Overload.
Types ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder embeds an env.Encoder and sets its target io.Writer to an os.File.
func Create ¶
Create returns a new Encoder which creates the file filename and uses it to write the encoded values to.
func NewEncoder ¶
NewEncoder returns a new Encoder which writes the encoded values to the provided os.File f.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func NewReader ¶
NewReader returns a Reader which looks up environment variables from the provided fs.File.
dec := env.NewDecoder(envfile.NewReader(file))
func Open ¶
Open opens filename for reading using os.Open and returns a new Reader. It is the caller's responsibility to close the Reader when finished. If there is an error, it will be of type *os.PathError.
func OpenFS ¶
OpenFS opens filename for reading from fsys and returns a new Reader. It is the caller's responsibility to close the Reader when finished. If there is an error, it will be of type *os.PathError.