env

package
v1.9.14 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: CC0-1.0 Imports: 5 Imported by: 0

README

godoc

Env

This small package give some functionality to common usage of detecting Tokopedia runtime ecosystem using TKPENV environment variable.

Other usecase is to set the environment variables using file, this is handy if you want to run your app in your laptop with custom value depending on your local ecosystem. For example your app will readDB_CONN to fetch connection string to database, you can create file containing envar to set before application initialize connection to database.

At default env will look for file .env in current directory and load the value. If you want to load env file from other place then you can use SetFromEnvFile(<path>).

Example

.env

DB_CONN=postgres://foo@bar/database

main.go

import _ "github.com/kodekoding/phastos/go/env" // this will enough just to trigger env to look for .env file

func main(){
    initializeDbConnection() // your function that read DB_CONN 
}

Documentation

Index

Constants

View Source
const (
	DevelopmentEnv = "development"
	StagingEnv     = "staging"
	ProductionEnv  = "production"
	LocalEnv       = "local"
)

Env list

Variables

View Source
var (
	Name = "APPS_ENV"
)

Env related var

Functions

func GoVersion

func GoVersion() string

GoVersion to return current build go version

func IsDevelopment

func IsDevelopment() bool

IsDevelopment return true when env is "development"

func IsLocal

func IsLocal() bool

IsLocal return true when env is "local"

func IsProduction

func IsProduction() bool

IsProduction return true when env is "production"

func IsStaging

func IsStaging() bool

IsStaging return true when env is "staging"

func SetFromEnvFile

func SetFromEnvFile(filepath string) error

SetFromEnvFile read env file and set the environment variables

Types

type ServiceNameEnv

type ServiceNameEnv = string

ServiceNameEnv type, not used anymore. Preserve to prevent breaking others.

func ServiceEnv

func ServiceEnv() ServiceNameEnv

ServiceEnv return ServiceENV service environment

Jump to

Keyboard shortcuts

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