env

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: MIT Imports: 2 Imported by: 3

README

Env

Get the machine's enviroment variables if they exist

Usage

In this example we overwrite the toml settings with the enviroment settings

func main() {
	c := config{}

	if err := toml.Unmarshal(file, &c); err != nil {
		panic(err)
	}
	
	if err := env.Unmarshal(&c); err != nil {
		panic(err)
	}

	setupWebContext(c)
}

type config struct {
	Cors []string `toml:"cors" env:"WEB_CORS"`
	DB   dbConfig `toml:"db"`
}

type dbConfig struct {
	Driver 	   string `toml:"driver" env:"DB_DRIVER"`
	Connection string `toml:"connection_string" env:"DB_STRING"`
}

Documentation

Overview

Package env is for parsing environment variables.

Usage

Create a struct that requires an environment variable and parse:

type dbConfig struct {
     ConnectionString string `toml:"connection_string" env:"DB_CONNECTION_STRING"`
     Driver           string `toml:"driver" env:"DB_DRIVER"`
}

func main() {
     conf := new(dbConfig)

     if err := env.Parse(conf); err != nil {
         ...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(obj interface{}) error

Parse reads the object and sets the properties to

Types

This section is empty.

Jump to

Keyboard shortcuts

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