NathanBurkett / env

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Documentation Coverage Status CircleCI Go Report Card

View the documentation

Install

go get -u github.com/nathanburkett/env

Usage

Reading an environmental file via Reader

package main

import (
    "fmt"
    "log"
    "github.com/nathanburkett/env"
    "os"
)

func main() {
    pwd, err := os.Getwd()
    if err != nil {
        log.Fatal(err)
    }

    readEnv(pwd)
}

func readEnv(workingDir string) {
    envPath := fmt.Sprintf("%s/.env", workingDir)

    file, err := os.Open(envPath)
    if err != nil {
        log.Panic(err)
	}
    defer file.Close()

    env.NewReader(file).Read()
}

Using Must()

package main

import (
    "github.com/jmoiron/sqlx"
    "github.com/nathanburkett/env"

    "log"
)

func main() {
    _, err := sqlx.Open("mysql", env.Must("DB_DSN"))
    if err != nil {
        log.Fatal(err)
    }

    // ...
}

Running tests

On MacOS you can install or upgrade to the latest released version with Homebrew:

brew install dep
brew upgrade dep

On other platforms you can use the install.sh script:

curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
make install -B
make coverage -B

License

Copyright (c) 2018 Nathan Burkett

Licensed under the MIT License

About

License:MIT License


Languages

Language:Go 75.9%Language:Shell 16.4%Language:Makefile 7.7%