dotenvconfig

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 6 Imported by: 0

README

DotEnvConfig

Library responsible for configuring Go applications.

Installation

go get github.com/andrewapj/dotenvconfig

Usage

Loading a config file
err := Load(getFS(), "config.env", Options{})
Config file

A config file should end with .env and its content should be in the following format:

TEST_KEY=123

# This is a comment

TEST_KEY2 = 456
Get Key

Get a key from the config

val, err := cfg.GetKey("KEY")
Get Key Must

Get a key from the config, panic if the key is missing

val := cfg.GetKeyMust("KEY")
Get Int Key

Get an integer value from the config.

i, err := cfg.GetKeyAsInt("TEST_KEY")
Get Int Key Must

Get an integer value from the config, panic if the key is missing

i := cfg.GetKeyAsIntMust("TEST_KEY")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConversion = errors.New("error, unable to convert value from string")
View Source
var ErrFsIsNil = errors.New("error, the FS was nil")
View Source
var ErrMissingKey = errors.New("error, could not find key")

Functions

func GetKey added in v0.7.0

func GetKey(key string) (string, error)

GetKey retrieves a value from the config by key.

func GetKeyAsInt added in v0.7.0

func GetKeyAsInt(key string) (int, error)

GetKeyAsInt retrieves a value from the config by key and converts the value to an int. If the key could not be found or the value can not be converted to an int, a zero is returned.

func GetKeyAsIntMust added in v0.8.0

func GetKeyAsIntMust(key string) int

GetKeyAsIntMust retrieves a value from the config by key and converts the value to an int. If the key could not be found or the value can not be converted to an int, the function will panic.

func GetKeyMust added in v0.8.0

func GetKeyMust(key string) string

GetKeyMust retrieves a value from the config by key. It panics if the key does not exist.

func Load added in v0.7.0

func Load(fSys fs.FS, path string, opts Options) error

Load reads the config from an env file and adds it to the environment. If an environment variable already exists then it is not overwritten.

Types

type Options added in v0.5.0

type Options struct {
	// JsonLogging indicates whether logging should be done in JSON format.
	JsonLogging bool

	// LoggingEnabled determines if logging is enabled for the library.
	LoggingEnabled bool
}

Options contains optional ways to configure an application.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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