github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/labels.go (about)

     1  package internal
     2  
     3  import "encoding/json"
     4  
     5  // Labels is used for connect JSON formatting.
     6  type Labels map[string]string
     7  
     8  // MarshalJSON requires a comment for golint?
     9  func (l Labels) MarshalJSON() ([]byte, error) {
    10  	ls := make([]struct {
    11  		Key   string `json:"label_type"`
    12  		Value string `json:"label_value"`
    13  	}, len(l))
    14  
    15  	i := 0
    16  	for key, val := range l {
    17  		ls[i].Key = key
    18  		ls[i].Value = val
    19  		i++
    20  	}
    21  
    22  	return json.Marshal(ls)
    23  }