readenv

package module
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 4 Imported by: 0

README

readenv

codecov Go Reference Build Status Go Report Card

A simple Go library to read environment variables files(.env files).

Installing

go get -u github.com/eddogola/readenv

Usage

The library basically parses the (file) byte data into a map, from which users can Get environment variables.

import (
    "os"

    "github.com/eddogola/readenv"
)

func main() {
    file, err := os.OpenFile(".env", os.O_RDONLY, 0444) // open .env file
    if err != nil {
        // handle error
    }
    defer file.Close()
    
    envData, err := readenv.ReadEnv(file)
    if err != nil {
        // handle error
    }

    val, err := envData.Get("<YOUR_.ENV_VAR>")) // access specific variables using their keys
    if err != nil {
        // handle error
    }
    fmt.Println(val)
}

Contribution

Feel free to

  • Start issues.
  • Make pull requests.
  • Make suggestions on improvement, e.g. features

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnvData

type EnvData map[string]string

EnvData maps environment keys to values.

func File

func File(filename string) (EnvData, error)

File takes in a filename, reads env vars from it and returns an EnvData

func Read added in v1.0.2

func Read(reader io.Reader) (EnvData, error)

Read takes in an io.Reader, reads env vars from it and returns an EnvData

func (EnvData) Get

func (data EnvData) Get(key string) (string, error)

Get returns the value of given key from the map, returns error if key not found

Jump to

Keyboard shortcuts

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