Home

Awesome

env

Tag-based environment configuration for structs.

Godoc Build Status Go Report Card

Installation

$ go get -u github.com/codingconcepts/env

Usage

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/codingconcepts/env"
)

type config struct {
	Secret            []byte        `env:"SECRET" required:"true"`
	Region            string        `env:"REGION"`
	Port              int           `env:"PORT" required:"true"`
	Peers             []string      `env:"PEERS"` // you can use `delimiter` tag to specify separator, for example `delimiter:" "` 
	ConnectionTimeout time.Duration `env:"TIMEOUT" default:"10s"`
}

func main() {
	c := config{}
	if err := env.Set(&c); err != nil {
		log.Fatal(err)
	}

	...
}
$ ID=1 SECRET=shh PORT=1234 PEERS=localhost:1235,localhost:1236 TIMEOUT=5s go run main.go

Supported field types