File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,23 @@ func (m *M) SetLabel(name string, value interface{}) {
75
75
}
76
76
}
77
77
78
+ // EditLabel calls edit with the current value of the specified label.
79
+ // The value returned by edit replaces the contents of the label.
80
+ // If edit returns nil, the label is removed from the set.
81
+ // If the label did not exist, the argument to edit is nil.
82
+ func (m * M ) EditLabel (name string , edit func (interface {}) interface {}) {
83
+ if m != nil {
84
+ m .mu .Lock ()
85
+ defer m .mu .Unlock ()
86
+ newValue := edit (m .label [name ])
87
+ if newValue == nil {
88
+ delete (m .label , name )
89
+ } else {
90
+ m .label [name ] = newValue
91
+ }
92
+ }
93
+ }
94
+
78
95
// Snapshot copies an atomic snapshot of the collected metrics into the non-nil
79
96
// fields of the provided snapshot value. Only the fields of snap that are not
80
97
// nil are snapshotted.
You can’t perform that action at this time.
0 commit comments