Skip to content

Commit d85fcd7

Browse files
committed
docs
1 parent bcc3c8f commit d85fcd7

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2013 Máximo Cuadros
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
go-defaults [![Build Status](https://travis-ci.org/mcuadros/go-defaults.png?branch=master)](https://travis-ci.org/mcuadros/go-defaults) [![GoDoc](https://godoc.org/github.com/mcuadros/go-defaults?status.png)](http://godoc.org/github.com/mcuadros/go-defaults)
2+
==============================
3+
4+
This library allow to define a default value to any struct, this is made thanks to [struct tags](http://golang.org/pkg/reflect/#StructTag).
5+
6+
> A StructTag is the tag string in a struct field.
7+
8+
> By convention, tag strings are a concatenation of optionally space-separated key:"value" pairs. Each key is a non-empty string consisting of non-control characters other than space (U+0020 ' '), quote (U+0022 '"'), and colon (U+003A ':'). Each value is quoted using U+0022 '"' characters and Go string literal syntax.
9+
10+
11+
Installation
12+
------------
13+
14+
The recommended way to install go-defaults
15+
16+
```
17+
go get github.com/mcuadros/go-defaults
18+
```
19+
20+
Examples
21+
--------
22+
23+
A basic example:
24+
25+
```go
26+
import "github.com/mcuadros/go-defaults"
27+
import "fmt"
28+
29+
type ExampleBasic struct {
30+
Foo bool `default:"true"`
31+
Bar string `default:"33"`
32+
Qux int8
33+
}
34+
35+
func NewExampleBasic() *ExampleBasic {
36+
example := new(ExampleBasic)
37+
SetDefaults(example)
38+
39+
return example
40+
}
41+
42+
...
43+
44+
test := NewExampleBasic()
45+
fmt.Println(test.Foo) //Prints: true
46+
fmt.Println(test.Bar) //Prints: 33
47+
fmt.Println(test.Qux) //Prints:
48+
49+
```
50+
51+
License
52+
-------
53+
54+
MIT, see [LICENSE](LICENSE)

0 commit comments

Comments
 (0)