-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
25 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,32 @@ | ||
package metrics | ||
|
||
// Label hold an map[string]interface{} value that can be set arbitrarily. | ||
type Label interface { | ||
Value() map[string]interface{} | ||
Mark(map[string]interface{}) | ||
// Label is the standard implementation of a Label. | ||
type Label struct { | ||
value map[string]interface{} | ||
} | ||
|
||
// NewRegisteredLabel constructs and registers a new StandardLabel. | ||
func NewRegisteredLabel(name string, r Registry) Label { | ||
c := NewStandardLabel() | ||
if nil == r { | ||
// GetOrRegisterLabel returns an existing Label or constructs and registers a | ||
// new Label. | ||
func GetOrRegisterLabel(name string, r Registry) *Label { | ||
if r == nil { | ||
r = DefaultRegistry | ||
} | ||
r.Register(name, c) | ||
return c | ||
return r.GetOrRegister(name, NewLabel).(*Label) | ||
} | ||
|
||
// NewStandardLabel constructs a new StandardLabel. | ||
func NewStandardLabel() *StandardLabel { | ||
return &StandardLabel{} | ||
} | ||
|
||
// StandardLabel is the standard implementation of a Label. | ||
type StandardLabel struct { | ||
value map[string]interface{} | ||
// NewLabel constructs a new Label. | ||
func NewLabel() *Label { | ||
return &Label{value: make(map[string]interface{})} | ||
} | ||
|
||
// Value returns label values. | ||
func (l *StandardLabel) Value() map[string]interface{} { | ||
func (l *Label) Value() map[string]interface{} { | ||
return l.value | ||
} | ||
|
||
// Mark records the label. | ||
func (l *StandardLabel) Mark(value map[string]interface{}) { | ||
l.value = value | ||
func (l *Label) Mark(value map[string]interface{}) { | ||
for k, v := range value { | ||
l.value[k] = v | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters