Skip to content

Latest commit

 

History

History
63 lines (45 loc) · 1.03 KB

README.md

File metadata and controls

63 lines (45 loc) · 1.03 KB

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