yihau / envstruct

a simple way to get your environment variable.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

envstruct

badge Go Report Card

a simple way to get your environment variable.

Getting Started

Installing

go get -v github.com/yihau/envstruct

Example

package main

import (
	"fmt"
	"log"

	"github.com/yihau/envstruct"
)

type Config struct {
	Host string `env:"HOST"`
	PORT int    `env:"PORT"`
}

func main() {
	var c Config
	err := envstruct.FillIn(&c)
	if err != nil {
		log.Fatalf("parse env config error, err: %v", err)
	}
	fmt.Printf("%+v\n", c)
}
export HOST=yihau.dev PORT=8080 && go run main.go
# {Host:yihau.dev PORT:8080}

Running the tests

go run cmd/gen_decode_test/main.go

go test -v ./...

License

This project is licensed under the MIT License

About

a simple way to get your environment variable.

License:MIT License


Languages

Language:Go 100.0%