File tree Expand file tree Collapse file tree 5 files changed +25
-4
lines changed
Expand file tree Collapse file tree 5 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 1- language : go
1+ language : go
2+
3+ script :
4+ - go get github.com/mcuadros/go-defaults
5+ - go test
Original file line number Diff line number Diff line change 1- Copyright (c) 2013 Máximo Cuadros
1+ Copyright (c) 2014 Máximo Cuadros
22
33Permission is hereby granted, free of charge, to any person obtaining a copy
44of this software and associated documentation files (the "Software"), to deal
Original file line number Diff line number Diff line change @@ -27,14 +27,14 @@ import "github.com/mcuadros/go-defaults"
2727import " fmt"
2828
2929type ExampleBasic struct {
30- Foo bool ` default:"true"`
30+ Foo bool ` default:"true"` // <-- StructTag with a default key
3131 Bar string ` default:"33"`
3232 Qux int8
3333}
3434
3535func NewExampleBasic () *ExampleBasic {
3636 example := new (ExampleBasic)
37- SetDefaults (example)
37+ SetDefaults (example) // <-- This set the defaults values
3838
3939 return example
4040}
Original file line number Diff line number Diff line change @@ -10,6 +10,18 @@ type Field struct {
1010 Value reflect.Value
1111}
1212
13+ // Apply the default values to the struct object, the struct type must have
14+ // the StructTag with name "default" and the directed value.
15+ //
16+ // Usage
17+ // type ExampleBasic struct {
18+ // Foo bool `default:"true"`
19+ // Bar string `default:"33"`
20+ // Qux int8
21+ // }
22+ //
23+ // foo := &ExampleBasic{}
24+ // SetDefaults(foo)
1325func SetDefaults (variable interface {}) {
1426 fields := getFields (variable )
1527 setDefaultValues (fields )
Original file line number Diff line number Diff line change 1+ /*
2+ This library allow to define a default value to any struct, this is made thanks
3+ to struct tags.
4+ */
5+ package defaults
You can’t perform that action at this time.
0 commit comments