env

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

README

env

This package tries to locate a .env or .env.local file in your app directory (or the parent directory). .env.local is prefered over .env and variables that are already existing will not be overridden.

Initialization

app := fx.New(
	env.Module,
)
app.Run()

Functions

env.GetEnvironment()

Will return the APP_ENV variables string value.

env.IsDevelopment()

Will return true if the APP_ENV variable is set to "dev". Useful to check if you are in development mode.

env.String("YOUR_ENV_VAR_NAME")

Returns the string value of your env variable.

env.StringWithDefault("YOUR_ENV_VAR_NAME", "your default")

Returns the string value of your env variable. If empty it will return the default string (in this case "your default").

env.Int("YOUR_ENV_VAR_NAME")

Returns the int value of your env variable.

env.IntWithDefault("YOUR_ENV_VAR_NAME", 123)

Returns the int value of your env variable. If empty it will return the default int (in this case 123).

env.Bool("YOUR_ENV_VAR_NAME")

Returns the bool value of your env variable (1 and "true" are equal to true).

env.BoolWithDefault("YOUR_ENV_VAR_NAME", true)

Returns the bool value of your env variable (1 and "true" are equal to true). If unset it will return the default bool (in this case true).

Documentation

Index

Constants

View Source
const APP_ENV = "APP_ENV"

Variables

View Source
var Module = fx.Provide(
	newEnvironment,
)

Functions

func Bool

func Bool(key string) bool

func BoolWithDefault

func BoolWithDefault(key string, defaultValue bool) bool

func GetEnvironment

func GetEnvironment() string

func Int

func Int(key string) int

func IntWithDefault

func IntWithDefault(key string, defaultValue int) int

func IsDevelopment

func IsDevelopment() bool

func String

func String(key string) string

func StringWithDefault

func StringWithDefault(key string, defaultValue string) string

Types

type Env

type Env struct{}

Jump to

Keyboard shortcuts

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