zdefaults

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2022 License: MIT Imports: 6 Imported by: 0

README

zdefaults

Set default values for a struct using tags. Will ignore any values that aren't at their zero value. Supports parsing time.Duration and time.Time.

Example

Set defaults for an example file server configuration.

type Config struct {
  Addr  string    `default:":80"`
  Roots []string  `default:"/var/www,/home/www"`
  Ints  []int     // ignored
}

func main () {
  conf := Config{}
  err = zdefaults.SetDefaults(&conf)
}
time.Time
type Config struct {
  Time          time.Time     `default:"2009-01-20"`
  CustomTime    time.Time     `default:"random-20-05-21" format:"random-06-01-02"`
  CacheDuration time.Duration `default:"10s"`
}

func main () {
  conf := FileServerConfig{}
  err = zdefaults.SetDefaults(&conf)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefaults

func SetDefaults(val interface{}) (err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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