labels.go 431 B

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