genvutils

package module
Version: v0.1.5-0...-9de41f3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2020 License: MIT Imports: 6 Imported by: 0

README

genvutils Go Report Card Build Status made-with-Go

Package genvutils provides useful environment operations

Funcs

  • IsProduction, IsDevelopment and IsTesting checks for ENVIRONMENT dot env value.
  • GetEnv gets env value or fallback which goes as second function argument.
  • Parse will fill given struct with env values or with fallbacks. (see examples folder)
	type serverConfig struct {
		ServerPort string `genv:"SERVER_PORT,8080"`
		MongoUrl   string `genv:"MONGO_URL,mongodb://localhost:27017"`
	}
  • Load will load dotenv file. You can provide file name via argument otherwise it will load dot environment file by priority list. First found - first load. Priority list:
.env.production.local
.env.test.local
.env.development.local
.env.production
.env.test
.env.development
.env.local !!! will override existing values.
.env

example

Install

go get -u github.com/lalabuy948/genvutils

Documentation

Overview

Package genvutils provides useful environment operations

Index

Constants

This section is empty.

Variables

View Source
var ErrDotenvNotFound = errors.New("genvutils: no dot environment files found")

Functions

func GetEnv

func GetEnv(key string, fallback string) string

GetEnv extracts env value by provided key, otherwise falls back to second function argument.

func IsDevelopment

func IsDevelopment() bool

IsDevelopment checks if ENVIRONMENT value is equal to "DEV" or "DEVELOPMENT".

func IsProduction

func IsProduction() bool

IsProduction checks if ENVIRONMENT value is equal to "PROD" or "PRODUCTION".

func IsStaging

func IsStaging() bool

IsStaging checks if ENVIRONMENT value is equal to "STAGE" or "STAGING".

func IsTesting

func IsTesting() bool

IsTesting checks if ENVIRONMENT value is equal to "TEST" or "TESTING".

func Load

func Load(filenames ...string) error

Load function is going to parse given dot environment file or chose one from priority list and set environment variables.

!!! It will not override already set variables. Except .env.local

Priority list is next (top -> bottom): .env.production.local .env.test.local .env.development.local .env.production .env.test .env.development .env.local !!! will override existing values. .env

func Parse

func Parse(income interface{}) error

Parse function will parse given pointer to struct and fill it with env values.

type serverConfig struct {
    ServerPort string `genv:"SERVER_PORT,8080"`
    MongoUrl   string `genv:"MONGO_URL,mongodb://localhost:27017"`
}

Here is an example of struct. Good reading about reflect https://github.com/a8m/reflect-examples

Types

This section is empty.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL