github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/helper/pluginutils/hclutils/types.go (about)

     1  package hclutils
     2  
     3  import (
     4  	"github.com/hashicorp/go-msgpack/codec"
     5  )
     6  
     7  // MapStrInt is a wrapper for map[string]int that handles
     8  // deserialization from different hcl2 json representation
     9  // that were supported in Nomad 0.8
    10  type MapStrInt map[string]int
    11  
    12  func (s *MapStrInt) CodecEncodeSelf(enc *codec.Encoder) {
    13  	v := []map[string]int{*s}
    14  	enc.MustEncode(v)
    15  }
    16  
    17  func (s *MapStrInt) CodecDecodeSelf(dec *codec.Decoder) {
    18  	ms := []map[string]int{}
    19  	dec.MustDecode(&ms)
    20  
    21  	r := map[string]int{}
    22  	for _, m := range ms {
    23  		for k, v := range m {
    24  			r[k] = v
    25  		}
    26  	}
    27  	*s = r
    28  }
    29  
    30  // MapStrStr is a wrapper for map[string]string that handles
    31  // deserialization from different hcl2 json representation
    32  // that were supported in Nomad 0.8
    33  type MapStrStr map[string]string
    34  
    35  func (s *MapStrStr) CodecEncodeSelf(enc *codec.Encoder) {
    36  	v := []map[string]string{*s}
    37  	enc.MustEncode(v)
    38  }
    39  
    40  func (s *MapStrStr) CodecDecodeSelf(dec *codec.Decoder) {
    41  	ms := []map[string]string{}
    42  	dec.MustDecode(&ms)
    43  
    44  	r := map[string]string{}
    45  	for _, m := range ms {
    46  		for k, v := range m {
    47  			r[k] = v
    48  		}
    49  	}
    50  	*s = r
    51  }