Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.2 KB

README.md

File metadata and controls

42 lines (30 loc) · 1.2 KB

flagbind

Go Reference

Package flagbind provides utilities to bind flags of GoLang's flag package to struct.

flagbind supports these types:

  • bool, *bool
  • int, *int
  • uint, *uint
  • int64, *int64
  • uint64, *uint64
  • int32, *int32
  • uint32, *uint32
  • string, *string
  • float64, *float64
  • float32, *float32
  • time.Duration, *time.Duration
  • flag.Value
  • func(value string) error
  • func(name string, value string) error

If exported known struct field has different type from given types, Bind method will panic. If struct field is unexported or anonymous, struct field will be ignored.

Field tags

name

The name tag defines flag name if it is given. Otherwise flag name will be generated by the example: MyFlag to -my-flag. If the name tag is -, struct field will be ignored.

usage

The usage tag defines flag usage by flag package.

default

The default tag defines default flag value by flag package. The default tag gets string value. When the default tag isn't given; if the struct field is pointer, default value is nil. Otherwise default value is initial value of struct field.