Skip to content

GoBike/envflag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

envflag

Go Report Card GoDoc

Simple environment extension to Golang flag.

Goals

  • Extends Golang flag with environment-variables.
  • Clear precendence: default < environment-variable < cli.
  • Adheres to 12-factor-app.

Installation

$ go get github.com/gobike/envflag

Usage

Create main.go

package main

import (
    "fmt"
    "flag"
    "github.com/gobike/envflag"
)

func main() {
    var (
        times int
    )

    flag.IntVar(&times, "f-times", 1, "this is #")
    envflag.Parse() 

    fmt.Println(times)
}

Run with default.

$ go run main.go 
1 #output

Run with environment-variable set.

$ F_TIMES=100 go run main.go 
100 #output

Run with cli set.

$ F_TIMES=100 go run main.go --f-times=10 
10 #output, environment-variable is ignored

About

Simple environment-variables extension to Golang flag.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages