owlinux1000 / go-envload

a tiny library to load enviroment variables to Golang struct.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-envload

go-envload is a tiny library to load enviroment variables to Golang struct.

  • Features
    • required attribute
    • default=hogehoge attribute
  • Not supported
    • Nested struct
    • automatic type cast

How to use

package main

import (
	"fmt"

	"github.com/owlinux1000/go-envload"
)

func main() {
	var cfg struct {
		User     string `env:"USER"`
		ApiToken string `env:"API_TOKEN,required"`
		Timeout  string `env:"TIMEOUT,default=60"`
	}
	if err := envload.Load(&cfg); err != nil {
		panic(err)
	}
	fmt.Printf("%v\n", cfg)
}

About

a tiny library to load enviroment variables to Golang struct.


Languages

Language:Go 100.0%