envie

package module
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

Go

envie

Welcome to envie! This project helps you read a full struct of env variables from your system. First, the Auto function will attempt to read the environment variables from the system. If it fails, it will attempt to recover by reading the values from a properties file. Default path is .env, see AutoPath. If both methods fail, it will panic if AutoPanic is set to true. (Default).

Installation

To install the library simply run:

$ go get github.com/da0x/envie

To import the library, use:

import "github.com/da0x/envie"

Usage

System Environment
$ export VARIABLE_ONE = hello
$ export VARIABLE_TWO = world
Properties File
// filename: .env
// this is a comment
VARIABLE_ONE = hello
VARIABLE_TWO = world
Code
type entity struct {
	V1 string `envie:"SOME_VAR1"`
	V2 string `envie:"SOME_VAR2"`
}

func main() {
	var e entity
    envie.Auto(&e)
    println(e)
}

Maintainer

Daher Alfawares

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AutoPanic = true
View Source
var AutoPath = ".env"
View Source
var AutoVerbose = true

Functions

func Auto

func Auto(e interface{})

Auto reads an struct of enironment variables from any of the following:

  1. Attempt to read env variables from the system.
  2. If the above fails, fall back to reading env from file. See AutoPath

If this function fails, it will panic if AutoPanic is set to true.

See AutoPanic

func Properties

func Properties(path string) (map[string]string, error)

Properties loads an environment file and returns it as a map[string]string. This is the best option for a lightweight env reader.

func UnmarshalFromFile added in v0.1.12

func UnmarshalFromFile(path string, e interface{}) error

UnmarshalFromFile attempts to read a struct from an existing env file. It will ignore any values not annotated as `envie="VAR_NAME"`. It returns an error if it fails.

func UnmarshalFromSystem added in v0.1.12

func UnmarshalFromSystem(e interface{}) error

UnmarshalFromSystem reads an entire struct of env variables. Returns an error if any of those variables does not exist in the environment.

Types

This section is empty.

Directories

Path Synopsis
Package props implements handling of property lists and files.
Package props implements handling of property lists and files.
r

Jump to

Keyboard shortcuts

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