env

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

env

env is a tiny package to handle environment variables in go application.

Install

go get github.com/anshuraghuvansi/env
OR in Go Mod file:
require (
	github.com/anshuraghuvansi/env v1.0.0
)

Getting Started

Create a file with the name of environment(Ex. development.env, testing.env etc) in root directory.

Put the variables in the file like this

PORT=8080
PASSWORD=YSG&*^HDHS

and then import the package in main package and configure the env

import (
	"env/env"
)

func main() {

	env.Configure()
  
}

Export the enviroment before runing the application For example

export environment=development

then run the go application using

go run main.go

now variable are available as env variable and can be access like this

import (
	"env/env"
	"fmt"
	"os"
)

func main() {

	env.Configure()

	port := os.Getenv("PORT")
	pwd := os.Getenv("PASSWORD")

	fmt.Println(port)
	fmt.Println(pwd)
	
	To get specific type of value 
	
	prod, ok := GetBoolValue("IS_PRODUCTION")
	if ok {
		fmt.Println(prod)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure()

Configure :

func GetBoolValue

func GetBoolValue(key string) (bool, bool)

GetBoolValue :

func GetFloat32Value

func GetFloat32Value(key string) (float32, bool)

GetFloat32Value :

func GetFloat64Value

func GetFloat64Value(key string) (float64, bool)

GetFloat64Value :

func GetInt8Value

func GetInt8Value(key string) (int8, bool)

GetInt8Value :

func GetInt16Value

func GetInt16Value(key string) (int16, bool)

GetInt16Value :

func GetInt32Value

func GetInt32Value(key string) (int32, bool)

GetInt32Value :

func GetInt64Value

func GetInt64Value(key string) (int64, bool)

GetInt64Value :

func GetIntValue

func GetIntValue(key string) (int, bool)

GetIntValue :

func GetValue

func GetValue(key string) string

GetValue :

func IsProduction

func IsProduction() bool

IsProduction :

Types

This section is empty.

Jump to

Keyboard shortcuts

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