env

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: BSD-3-Clause Imports: 4 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.

Usage

//go:build wireinject

package app

import (
	"github.com/fraym-work/go-wire-core/env"
	"github.com/google/wire"
)

func New() *env.Env {
	wire.Build(
		env.New,
	)
	return nil
}

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

This section is empty.

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{}

func New

func New() *Env

Jump to

Keyboard shortcuts

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