forked from lleiiell/goist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct_test.go
More file actions
55 lines (45 loc) · 940 Bytes
/
struct_test.go
File metadata and controls
55 lines (45 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package goist
import "fmt"
func ExampleStruct2Map() {
st := struct {
Name string `json:"name,omitempty"`
True bool `json:"true"`
}{
"till",
true,
}
// m, err := Struct2Map(st)
// fmt.Println(m["name"], m["true"], err)
// Output: till true <nil>
fmt.Println(Struct2Map(st))
// Output: map[name:till true:true] <nil>
}
func ExampleStruct2Str() {
st := struct {
Name string `json:"name,omitempty"`
True bool `json:"true"`
Title string
}{
"till",
true,
"title",
}
// m, err := Struct2Map(st)
// fmt.Println(m["name"], m["true"], err)
// Output: till true <nil>
fmt.Println(Struct2Str(st, "", ""))
// Output: name,true,Title <nil>
}
func ExampleStruct2StrAndWrap() {
st := struct {
Name string `json:"name,omitempty"`
True bool `json:"true"`
Title string
}{
"till",
true,
"title",
}
fmt.Println(Struct2StrAndWrap(st, "", "", "`"))
// Output: `name`,`true`,`Title` <nil>
}