zdefaults

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: MIT Imports: 7 Imported by: 0

README

zdefaults

Set default values for a struct using tags. Will ignore any values that aren't already at their zero value. Supports parsing time.Duration and time.Time as well as custom implementations of the Settable interface.

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" time-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 Set added in v0.8.6

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

Types

type Settable added in v0.9.1

type Settable interface {
	Set(val string) error
	String() string
}

Jump to

Keyboard shortcuts

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