Logo

0x5a.live

for different kinds of informations and explorations.

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

Tag-based environment configuration for structs. Contribute to codingconcepts/env development by creating an account on GitHub.

Visit SiteGitHub - codingconcepts/env: Tag-based environment configuration for structs

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

Tag-based environment configuration for structs. Contribute to codingconcepts/env development by creating an account on GitHub.

Powered by 0x5a.live ๐Ÿ’—

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

  • 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

GoLang Resources

are all listed below.

Resources

listed to get explored on!!

Made with โค๏ธ

to provide different kinds of informations and resources.