-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
types.go
51 lines (42 loc) · 1.06 KB
/
types.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
package hclutils
import (
"github.com/hashicorp/go-msgpack/codec"
)
// MapStrInt is a wrapper for map[string]int that handles
// deserialization from different hcl2 json representation
// that were supported in Nomad 0.8
type MapStrInt map[string]int
func (s *MapStrInt) CodecEncodeSelf(enc *codec.Encoder) {
v := []map[string]int{*s}
enc.MustEncode(v)
}
func (s *MapStrInt) CodecDecodeSelf(dec *codec.Decoder) {
ms := []map[string]int{}
dec.MustDecode(&ms)
r := map[string]int{}
for _, m := range ms {
for k, v := range m {
r[k] = v
}
}
*s = r
}
// MapStrStr is a wrapper for map[string]string that handles
// deserialization from different hcl2 json representation
// that were supported in Nomad 0.8
type MapStrStr map[string]string
func (s *MapStrStr) CodecEncodeSelf(enc *codec.Encoder) {
v := []map[string]string{*s}
enc.MustEncode(v)
}
func (s *MapStrStr) CodecDecodeSelf(dec *codec.Decoder) {
ms := []map[string]string{}
dec.MustDecode(&ms)
r := map[string]string{}
for _, m := range ms {
for k, v := range m {
r[k] = v
}
}
*s = r
}