envfile

package
v0.4.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: BSD-3-Clause Imports: 9 Imported by: 3

Documentation

Overview

Package envfile provides tools to read and load environment variables from files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate added in v0.4.4

func Generate(dir, filename string, src any) error

Generate encodes and writes an env file in dir based on the provided src. It is meant to be used with go generate to create .env files based on the project's config(s).

func Load

func Load(filename string) error

Load reads from filename and sets the environment variables using env.Load.

func LoadFS

func LoadFS(fsys fs.FS, filename string) error

LoadFS reads from filename and sets the environment variables using env.Load.

func Overload

func Overload(filename string) error

Overload reads from filename and sets and overwrites the environment variables using env.Overload.

func OverloadFS

func OverloadFS(fsys fs.FS, filename string) error

OverloadFS reads from filename and sets and overwrites the environment variables using env.Overload.

func Write

func Write(filename string, v any) (err error)

Write creates the file filename using Create, writes the encoded value v to it and closes its internal file handle.

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

func Create(filename string) (*Encoder, error)

Create returns a new Encoder which creates the file filename and uses it to write the encoded values to.

func NewEncoder

func NewEncoder(f *os.File) *Encoder

NewEncoder returns a new Encoder which writes the encoded values to the provided os.File f.

func (*Encoder) Close

func (fe *Encoder) Close() error

Close closes its internal os.File.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(f fs.File) *Reader

NewReader returns a Reader which looks up environment variables from the provided fs.File.

dec := env.NewDecoder(envfile.NewReader(file))

func Open

func Open(filename string) (*Reader, error)

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

func OpenFS(fsys fs.FS, filename string) (*Reader, error)

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.

func (*Reader) Close

func (f *Reader) Close() error

Close closes the underlying fs.File.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL