« Back to Search  |  Reader Mode  |  Switch to Full Retro Site View Links: Stay in Reader  |  Retro Mode: ON  |  Original »
GitHub · Extracted in 685 ms

GitHub - codingconcepts/env: Tag-based environment configuration for structs

Source: https://github.com/codingconcepts/env

Repository navigation

env
Public

About

Tag-based environment configuration for structs

Resources

Readme MIT license Activity

Stars

125 stars

Watchers

1 watching

Forks

14 forks Report repository
Branches

Tags
Go to Branches page Go to Tags page

Latest commit

 

History


68 Commits
View commit history for this file.

Folders and files

Name Name Last commit message Last commit date
.gitignore .gitignore    
.travis.yml .travis.yml    
LICENSE LICENSE    
Makefile Makefile    
README.md README.md    
common_test.go common_test.go    
doc.go doc.go    
env.go env.go    
envExampleSet_test.go envExampleSet_test.go    
env_test.go env_test.go    
go.mod go.mod    
set.go set.go    

Repository files navigation

env

Tag-based environment configuration for structs.

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

  • bool and []bool
  • string and []string
  • []byte
  • int, int8, int16, int32, int64, []int, []int8, []int16, []int32, and []int64
  • uint, uint8, uint16, uint32, uint64, []uint, []uint8, []uint16, []uint32, and []uint64
  • float32, float64, []float32, and []float64
  • time.Duration and []time.Duration

About

Tag-based environment configuration for structs

Resources

Readme MIT license Activity

Stars

125 stars

Watchers

1 watching

Forks

14 forks Report repository

Releases

Packages

Used by

Contributors

Languages