Skip to content

Commit ea0a41d

Browse files
committed
documentation
1 parent d85fcd7 commit ea0a41d

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
language: go
1+
language: go
2+
3+
script:
4+
- go get github.com/mcuadros/go-defaults
5+
- go test

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2013 Máximo Cuadros
1+
Copyright (c) 2014 Máximo Cuadros
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ import "github.com/mcuadros/go-defaults"
2727
import "fmt"
2828

2929
type 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

3535
func NewExampleBasic() *ExampleBasic {
3636
example := new(ExampleBasic)
37-
SetDefaults(example)
37+
SetDefaults(example) //<-- This set the defaults values
3838

3939
return example
4040
}

defaults.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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)
1325
func SetDefaults(variable interface{}) {
1426
fields := getFields(variable)
1527
setDefaultValues(fields)

doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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

0 commit comments

Comments
 (0)