flagx

package module
v0.0.0-...-7cf7c6c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 4 Imported by: 12

README

go-flagx

this package is flag extentions. for me

Usage

  • StringSlice
// command -name taro -name hanako -name jiro
var names = flagx.StringSlice([]string)
flag.Var(&names, "name", "name list")
flag.Parse()

// names = []string{"taro", "hanako", "jiro"}
  • EnvToFlagWithPrefix
// APP_NAME=foo APP_PORT=5000 command
var (
    name string
    port int
)
flag.StringVar(&name, "name", "", "set name") 
flag.IntVar(&port, "port", 8080, "listen port")
flag.VisitAll(flagx.EnvToFlagWithPrefix("APP_"))
flag.Parse()

// name = "foo", port = 5000

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnvToFlag = EnvToFlagWithPrefix("")

EnvToFlag is func for set to flag value from enviroments

Functions

func EnvToFlagWithPrefix

func EnvToFlagWithPrefix(prefix string) func(f *flag.Flag)

EnvToFlagWithPrefix return the func for set to flag value from enviroments value with prefix

Types

type StringSlice

type StringSlice []string

StringSlice is a implemented `flag.Value` for string slice

func (*StringSlice) Set

func (ss *StringSlice) Set(s string) error

func (*StringSlice) String

func (ss *StringSlice) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL