-
-
Notifications
You must be signed in to change notification settings - Fork 366
/
tag.go
45 lines (37 loc) · 966 Bytes
/
tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package app
// Tagger is the interface that describes a collection of tags that gives
// context to something.
type Tagger interface {
// Returns a collection of tags.
Tags() Tags
}
// Tags represent key-value pairs that give context to what they are used with.
type Tags map[string]string
func (t Tags) Tags() Tags {
return t
}
// Set sets a tag with the given name and value. The value is converted to a
// string.
func (t Tags) Set(name string, v interface{}) {
t[name] = toString(v)
}
// Get returns a tag value with the given name.
func (t Tags) Get(name string) string {
return t[name]
}
// Tag is a key-value pair that adds context to an action.
type Tag struct {
Name string
Value string
}
func (t Tag) Tags() Tags {
return Tags{t.Name: t.Value}
}
// T creates a tag with the given name and value. The value is converted to a
// string.
func T(name string, value interface{}) Tag {
return Tag{
Name: name,
Value: toString(value),
}
}