dotenv

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 8 Imported by: 11

README

GoDoc CI CodeQL Go Report Card Coverage Status

DotEnv

GoLobby DotEnv is a lightweight package for loading OS environment variables into structs in 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      `dotenv:"DEBUG"`
    App struct {
        Name string `dotenv:"APP_NAME"`
        Port int16  `dotenv:"APP_PORT"`
    }
    Database struct {
        Name string `dotenv:"DB_NAME"`
        Port int16  `dotenv:"DB_PORT"`
        User string `dotenv:"DB_USER"`
        Pass string `dotenv:"DB_PASS"`
    }
}

c := Config{}
f, err := os.Open(".env")
err = dotenv.Load(f, &c)

// Use `c` struct in your app!

See Also

  • GoLobby/Config: A lightweight yet powerful config package 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.

Documentation

Overview

Package dotenv is a lightweight library for loading dot env (.env) files into structs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(file *os.File, structure interface{}) error

Load reads a dot env (.env) file and fills the given struct fields.

Types

This section is empty.

Jump to

Keyboard shortcuts

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