Skip to content

klebed/go-defaults

 
 

Repository files navigation

go-defaults Build Status GoDoc GitHub release

Enabling stuctures with defaults values using struct tags.

Installation

The recommended way to install go-defaults

go get gopkg.in/mcuadros/go-defaults.v1

Examples

A basic example:

import (
    "fmt"
    "github.com/mcuadros/go-defaults"
)

type ExampleBasic struct {
    Foo bool   `default:"true"` //<-- StructTag with a default key
    Bar string `default:"33"`
    Qux int8
}

func NewExampleBasic() *ExampleBasic {
    example := new(ExampleBasic)
    defaults.SetDefaults(example) //<-- This set the defaults values

    return example
}

...

test := NewExampleBasic()
fmt.Println(test.Foo) //Prints: true
fmt.Println(test.Bar) //Prints: 33
fmt.Println(test.Qux) //Prints:

License

MIT, see LICENSE

About

Go structures with default values using tags

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%