github.com/newrelic/go-agent@v3.26.0+incompatible/internal/labels.go (about)

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