Go minimalist typed environment variables library

Typenv

go.dev go report codecov

Typenv is a minimalistic, zero dependency, typed environment variables library. It does support the following types:

  • Bool
  • Duration
  • Float64
  • Float32
  • Int64
  • Int32
  • Int8
  • Int
  • String

Why typenv?

Handling environment variables in other type than strings or even handling fallback values is not a simple task, typenv makes easy to handle string, boolean, integer, float and time duration environment variables and also allows you to easily set default values for then.

How to use it

Basic usage

Go get the library:

go get diegomarangoni.dev/typenv

And use it:

if typenv.Bool("DEBUG") {
	// do something
}

If the environment is NOT set, the zero value of the type will return, in this case false.

With default value

You can fallback to a default value in case the environment variable is not set.

if typenv.Bool("DEBUG", true) {
	// do something
}

If the environment is NOT set, the return value will be true.

With global default value

You can also set a global default value for a environment. Useful when you use the same environment with same default value several times.

func init() {
	typenv.SetGlobalDefault(
		typenv.E(typenv.Bool, "DEBUG", true),
	)
}

...

if typenv.Bool("DEBUG") {
	// do something
}

If the environment is NOT set, the return value will be true.

Overriding global default value

You still can override the global default value by setting a local default.

func init() {
	typenv.SetGlobalDefault(
		typenv.E(typenv.Bool, "DEBUG", true),
	)
}

...

if typenv.Bool("DEBUG", false) {
	// do something
}

If environment is NOT set, the return value will be false, even if global default is telling that is true.

Similar Resources

Go Trusted Execution Environment (TEE)

Go Trusted Execution Environment (TEE)

Introduction The GoTEE framework implements concurrent instantiation of TamaGo based unikernels in privileged and unprivileged modes, interacting with

Dec 5, 2022

Interactive Cloud-Native Environment Client

Interactive Cloud-Native Environment Client

Fenix-CLI:Interactive Cloud-Native Environment Client English | 简体中文 Fenix-CLI is an interactive cloud-native operating environment client. The goal i

Dec 15, 2022

A penetration toolkit for container environment

ctrsploit: A penetration toolkit for container environment 中文文档 Pre-Built Release https://github.com/ctrsploit/ctrsploit/releases Usage Quick-Start wg

Dec 6, 2022

The OCI Service Operator for Kubernetes (OSOK) makes it easy to connect and manage OCI services from a cloud native application running in a Kubernetes environment.

OCI Service Operator for Kubernetes Introduction The OCI Service Operator for Kubernetes (OSOK) makes it easy to create, manage, and connect to Oracle

Sep 27, 2022

Environment-driven Docker credential helper

Docker Credentials from the Environment A docker credential helper to streamline repository interactions in CI/CD pipelines, particularly Jenkins decl

Jul 13, 2022

Development environment for golang

docker-go-sample Development environment for golang Build docker-compose up -d -

Dec 17, 2021

Gottago - 💨 My personal development environment for golang.

gottago This repo contains my personal development environment for golang. Preparation Run docker app. Change the current working directory and execut

Jan 2, 2022

Frep - Generate file using template from environment, arguments, json/yaml/toml config files

frep Generate file using template from environment, arguments, json/yaml/toml config files. NAME: frep - Generate file using template USAGE: fr

Nov 30, 2022

Docker-NodeJS - Creating a CI/CD Environment for Serverless Containers on Google Cloud Run

Docker-NodeJS - Creating a CI/CD Environment for Serverless Containers on Google Cloud Run

Creating a CI/CD Environment for Serverless Containers on Google Cloud Run Archi

Jan 8, 2022
Shiba - Minimalist Kubernetes network plugin

Shiba(柴) Shiba is a minimalist Kubernetes network plugin, as a replacement for f

Sep 12, 2022
Testcontainers is a Golang library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.

When I was working on a Zipkin PR I discovered a nice Java library called Testcontainers. It provides an easy and clean API over the go docker sdk to

Jan 7, 2023
AWS environment config loader

awsenv AWS environment config loader. awsenv is a small binary that loads AWS environment variables for an AWS profile from ~/.aws/credentials - usefu

Nov 28, 2022
A multi-service dev environment for teams on Kubernetes
A multi-service dev environment for teams on Kubernetes

Tilt Kubernetes for Prod, Tilt for Dev Modern apps are made of too many services. They're everywhere and in constant communication. Tilt powers multi-

Jan 5, 2023
:recycle: Now you can easily rollback to previous deployed images whatever you want on k8s environment

EasyRollback EasyRollback is aim to easy rollback to previous images that deployed on k8s environment Installation You should have go installation fir

Dec 24, 2022
Open URL in your local web browser from the SSH-connected remote environment.

opener Open URL in your local web browser from the SSH-connected remote environment. How does opener work? opener is a daemon process that runs locall

Oct 20, 2022
A tool to build, deploy, and release any environment using System Containers.
A tool to build, deploy, and release any environment using System Containers.

Bravetools Bravetools is an end-to-end System Container management utility. Bravetools makes it easy to configure, build, and deploy reproducible envi

Dec 14, 2022
Sample multi docker compose environment setup

Instructions This is a demonstration of a Multi Docker Compose. The purpose of this repositoy is ongoing research on "Docker compose" architecture des

Oct 21, 2022
Stackie enables developers to configure their local environment/toolchain with ease.

Stackie enables developers to configure their local environment/toolchain with ease. Made for Pulumi CLI, Google Cloud Platform (gcloud), and Amazon Web Services (aws-cli).

Sep 10, 2021
fiber-air-docker development environment boilerplate, examples
fiber-air-docker development environment boilerplate, examples

ON AIR! fiber-air-docker development environment boilerplate TODO on air 세션 준비 fiber 유저 준비 gorm 외래키 준비 아키텍쳐 참고 https://blog.puppyloper.com/menus/Golan

Sep 14, 2022