forked from mitchellh/hashstructure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashstructure_examples_test.go
61 lines (52 loc) · 1.09 KB
/
hashstructure_examples_test.go
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
56
57
58
59
60
61
package hashstructure
import (
"crypto/sha256"
"fmt"
)
func ExampleHash() {
type ComplexStruct struct {
Name string
Age uint
Metadata map[string]interface{}
}
v := ComplexStruct{
Name: "mitchellh",
Age: 64,
Metadata: map[string]interface{}{
"car": true,
"location": "California",
"siblings": []string{"Bob", "John"},
},
}
hasher := sha256.New()
_, err := Hash(v, FormatV2, &HashOptions{Hasher: hasher})
if err != nil {
panic(err)
}
fmt.Printf("%d", hasher.Sum(nil))
// Output:
// [59 211 209 211 148 28 150 169 196 203 223 172 124 19 44 68 61 179 84 224 195 75 194 37 64 184 169 150 146 17 214 37]
}
func ExampleHash_v1() {
type ComplexStruct struct {
Name string
Age uint
Metadata map[string]interface{}
}
v := ComplexStruct{
Name: "mitchellh",
Age: 64,
Metadata: map[string]interface{}{
"car": true,
"location": "California",
"siblings": []string{"Bob", "John"},
},
}
hash, err := Hash(v, FormatV1, nil)
if err != nil {
panic(err)
}
fmt.Printf("%d", hash)
// Output:
// [8 54 108 169 168 105 61 236]
}