GoLobby DotEnv is a lightweight package for loading dot env (.env) files into structs for Go projects

GoDoc CI CodeQL Go Report Card Coverage Status

DotEnv

GoLobby DotEnv is a lightweight package for loading dot env (.env) files into structs for Go projects

Documentation

Supported Versions

It requires Go v1.11 or newer versions.

Installation

To install this package run the following command in the root of your project.

go get github.com/golobby/dotenv

Usage Example

Sample .env file:

DEBUG=true

APP_NAME=MyApp
APP_PORT=8585

DB_NAME=shop
DB_PORT=3306
DB_USER=root
DB_PASS=secret

Sample .go file:

type Config struct {
    Debug bool      `env:"DEBUG"`
    App struct {
        Name string `env:"APP_NAME"`
        Port int16  `env:"APP_PORT"`
    }
    Database struct {
        Name string `env:"DB_NAME"`
        Port int16  `env:"DB_PORT"`
        User string `env:"DB_USER"`
        Pass string `env:"DB_PASS"`
    }
}

config := Config{}
file, err := os.Open(".env")

err = dotenv.NewDecoder(file).Decode(&config)

// Use `config` struct in your app!

Usage Tips

  • The Decode() function gets a pointer of a struct.
  • It ignores the fields that have no related environment variables in the file.
  • It supports nested structs and struct pointers.

Field Types

GoLobby DotEnv uses the GoLobby Cast package to cast environment variables to related struct field types. Here you can see the supported types:

https://github.com/golobby/cast#supported-types

See Also

  • GoLobby/Config: A lightweight yet powerful configuration management for Go projects
  • GoLobby/Env: A lightweight package for loading OS environment variables into structs for Go projects

License

GoLobby DotEnv is released under the MIT License.

Owner
GoLobby
GoLobby publishes open source packages with simplicity and fluent APIs in mind for GoLang
GoLobby
Similar Resources

A Go port of Ruby's dotenv library (Loads environment variables from `.env`.)

GoDotEnv A Go (golang) port of the Ruby dotenv project (which loads env vars from a .env file) From the original Library: Storing configuration in the

Jan 5, 2023

Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

Dec 29, 2022

Split multiple Kubernetes files into smaller files with ease. Split multi-YAML files into individual files.

kubectl-slice: split Kubernetes YAMLs into files kubectl-slice is a neat tool that allows you to split a single multi-YAML Kubernetes manifest into mu

Jan 3, 2023

Envopts - Provides a code generator for turning env structs into functional options

envopts Provides a code generator to turn structs annotated for the popular env

Jan 10, 2022

Automatically generate Go Code from dotenv files.

goenvgen Automatically generate Go Code from dotenv files. This cli automatically determines the type information from the dotenv information and gene

Dec 3, 2021

Library for setting values to structs' fields from env, flags, files or default tag

Configuration is a library for injecting values recursively into structs - a convenient way of setting up a configuration object. Available features:

Dec 7, 2022

Clones github projects into ~/Projects/github/{org}/{repo}

Tidy clone Github cli extension (gh extension) to clone repos into ~/Projects/github/{org}/{repo} on the local filesystem Install gh extension install

Jan 19, 2022

Converts 'go mod graph' output into Graphviz's DOT language

Converts 'go mod graph' output into Graphviz's DOT language

modgv Converts 'go mod graph' output into GraphViz's DOT language. takes no options or arguments it reads the output generated by “go mod graph” on st

Dec 22, 2022

K8s-go-structs - All k8s API Go structs

k8s-api go types Why? Its nice to have it all in a single package. . |-- pkg |

Jul 17, 2022

A simple dotenv for golang

Простая читалка файлов .env Начало работы Загрузите необходимый репозиторий go g

Jan 5, 2022

Snapshot - snapshot provides a set of utility functions for creating and loading snapshot files for using snapshot tests.

Snapshot - snapshot provides a set of utility functions for creating and loading snapshot files for using snapshot tests.

Jan 27, 2022

Allows parsing CSV files into custom structs and implements required fields that can't be empty

Welcome to Go Custom CSV Parser 👋 Allows parsing CSV files into custom structs and implements required fields that can't be empty 🏠 Homepage Install

Nov 9, 2021

A Go (golang) environment loader (which loads env vars from a .env file)

A Go (golang) environment loader (which loads env vars from a .env file)

Feb 8, 2022

🔄 Maintain a local copy of you dot files

Dotup This command line is in charge of maintaining a local copy of you dot files from a source folder. It copies all the files in the source fold

Oct 20, 2021

Knit is an inline code generation tool that combines the power of Go's text/template package with automatic spec file loading.

Knit Knit is an inline code generation tool that combines the power of Go's text/template package with automatic spec file loading. Example openapi: "

Sep 15, 2022

Tool to visualize the graph of embedded structs in Go projects

Tool to visualize the graph of embedded structs in Go projects

Visualize a hierarchy of embedded Go structs This tool scans a directory of Go source code files to create a visualization of struct embedding in the

Nov 27, 2022

Go package for writing descriptions using the Graphviz DOT language

Go package for writing descriptions using the Graphviz DOT language

dot - little helper package in Go for the graphviz dot language

Nov 30, 2022

Genv is a library for Go (golang) that makes it easy to read and use environment variables in your projects. It also allows environment variables to be loaded from the .env file.

genv Genv is a library for Go (golang) that makes it easy to read and use environment variables in your projects. It also allows environment variables

Dec 21, 2022
Comments
  • Regex: support multiline values

    Regex: support multiline values

    Hey! I'm just learning how to write using golang, so excuse me if I made stupid errors.

    In this request I made support for multi-line values using regex.

    Is this idea ok?

Package manager for future projects

PCKGER is a package manager for my next project but when it will be able to build binaries and move libs it will be used like a normal package manager

Dec 20, 2021
Go Package Manager (gopm) is a package manager and build tool for Go.

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? In favor of Go Modules Proxy since Go 1.11, this pr

Dec 14, 2022
Package Management for Golang
Package Management for Golang

Glide: Vendor Package Management for Golang Are you used to tools such as Cargo, npm, Composer, Nuget, Pip, Maven, Bundler, or other modern package ma

Dec 27, 2022
Package core is a service container that elegantly bootstrap and coordinate twelve-factor apps in Go.

Package core is a service container that elegantly bootstrap and coordinate twelve-factor apps in Go. Background The twelve-factor methodology has pro

Nov 3, 2022
🦄 Easy, fast and open-source local package manager for Python!

Unikorn ?? Easy, fast and open-source local package manager for Python! Key Features Speed: You can add a package in one second.

Dec 11, 2021
gPac - a linux package manager

gPac is a useless package manager. It is included in the gSuite, which is a suite of tools written in GO. gPac is a KISS - like package manager.

Mar 13, 2022
GoFish is a cross-platform systems package manager, bringing the ease of use of Homebrew to Linux and Windows.

GoFish is a cross-platform systems package manager, bringing the ease of use of Homebrew to Linux and Windows.

Dec 11, 2022
gobin is a package manager for /go/bin

gobin gobin is a package manager for /go/bin Features List installed packages. Check for updates. Install packages (like go install). Uninstall packag

Nov 12, 2022
📦 An independent package manager for compiled binaries.
📦 An independent package manager for compiled binaries.

stew An independent package manager for compiled binaries. Features Easily distribute binaries across teams and private repositories. Get the latest r

Dec 13, 2022
K8s-dotenv - Kubernetes Secrets and Configmaps to dot env file

k8s-dotenv A commandline tool to fetch, merge and convert secrets and config map

Apr 22, 2022