Debian Codegraph @

event/keys/keys.go

raw symbols SCIP
1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package keys
6
7 import (
8 "golang.org/x/exp/event"
9 )
10
11 // Value represents a key for untyped values.
12 type Value string
13
14 // From can be used to get a value from a Label.
15 func (k Value) From(l event.Label) interface{} { return l.Interface() }
16
17 // Of creates a new Label with this key and the supplied value.
18 func (k Value) Of(v interface{}) event.Label {
19 return event.Value(string(k), v)
20 }
21
22 // Tag represents a key for tagging labels that have no value.
23 // These are used when the existence of the label is the entire information it
24 // carries, such as marking events to be of a specific kind, or from a specific
25 // package.
26 type Tag string
27
28 // New creates a new Label with this key.
29 func (k Tag) New() event.Label {
30 return event.Label{Name: string(k)}
31 }
32
33 // Int represents a key
34 type Int string
35
36 // Of creates a new Label with this key and the supplied value.
37 func (k Int) Of(v int) event.Label {
38 return event.Int64(string(k), int64(v))
39 }
40
41 // From can be used to get a value from a Label.
42 func (k Int) From(l event.Label) int { return int(l.Int64()) }
43
44 // Int8 represents a key
45 type Int8 string
46
47 // Of creates a new Label with this key and the supplied value.
48 func (k Int8) Of(v int8) event.Label {
49 return event.Int64(string(k), int64(v))
50 }
51
52 // From can be used to get a value from a Label.
53 func (k Int8) From(l event.Label) int8 { return int8(l.Int64()) }
54
55 // Int16 represents a key
56 type Int16 string
57
58 // Of creates a new Label with this key and the supplied value.
59 func (k Int16) Of(v int16) event.Label {
60 return event.Int64(string(k), int64(v))
61 }
62
63 // From can be used to get a value from a Label.
64 func (k Int16) From(l event.Label) int16 { return int16(l.Int64()) }
65
66 // Int32 represents a key
67 type Int32 string
68
69 // Of creates a new Label with this key and the supplied value.
70 func (k Int32) Of(v int32) event.Label {
71 return event.Int64(string(k), int64(v))
72 }
73
74 // From can be used to get a value from a Label.
75 func (k Int32) From(l event.Label) int32 { return int32(l.Int64()) }
76
77 // Int64 represents a key
78 type Int64 string
79
80 // Of creates a new Label with this key and the supplied value.
81 func (k Int64) Of(v int64) event.Label {
82 return event.Int64(string(k), v)
83 }
84
85 // From can be used to get a value from a Label.
86 func (k Int64) From(l event.Label) int64 { return l.Int64() }
87
88 // UInt represents a key
89 type UInt string
90
91 // Of creates a new Label with this key and the supplied value.
92 func (k UInt) Of(v uint) event.Label {
93 return event.Uint64(string(k), uint64(v))
94 }
95
96 // From can be used to get a value from a Label.
97 func (k UInt) From(l event.Label) uint { return uint(l.Uint64()) }
98
99 // UInt8 represents a key
100 type UInt8 string
101
102 // Of creates a new Label with this key and the supplied value.
103 func (k UInt8) Of(v uint8) event.Label {
104 return event.Uint64(string(k), uint64(v))
105 }
106
107 // From can be used to get a value from a Label.
108 func (k UInt8) From(l event.Label) uint8 { return uint8(l.Uint64()) }
109
110 // UInt16 represents a key
111 type UInt16 string
112
113 // Of creates a new Label with this key and the supplied value.
114 func (k UInt16) Of(v uint16) event.Label {
115 return event.Uint64(string(k), uint64(v))
116 }
117
118 // From can be used to get a value from a Label.
119 func (k UInt16) From(l event.Label) uint16 { return uint16(l.Uint64()) }
120
121 // UInt32 represents a key
122 type UInt32 string
123
124 // Of creates a new Label with this key and the supplied value.
125 func (k UInt32) Of(v uint32) event.Label {
126 return event.Uint64(string(k), uint64(v))
127 }
128
129 // From can be used to get a value from a Label.
130 func (k UInt32) From(l event.Label) uint32 { return uint32(l.Uint64()) }
131
132 // UInt64 represents a key
133 type UInt64 string
134
135 // Of creates a new Label with this key and the supplied value.
136 func (k UInt64) Of(v uint64) event.Label {
137 return event.Uint64(string(k), v)
138 }
139
140 // From can be used to get a value from a Label.
141 func (k UInt64) From(l event.Label) uint64 { return l.Uint64() }
142
143 // Float32 represents a key
144 type Float32 string
145
146 // Of creates a new Label with this key and the supplied value.
147 func (k Float32) Of(v float32) event.Label {
148 return event.Float64(string(k), float64(v))
149 }
150
151 // From can be used to get a value from a Label.
152 func (k Float32) From(l event.Label) float32 { return float32(l.Float64()) }
153
154 // Float64 represents a key
155 type Float64 string
156
157 // Of creates a new Label with this key and the supplied value.
158 func (k Float64) Of(v float64) event.Label {
159 return event.Float64(string(k), v)
160 }
161
162 // From can be used to get a value from a Label.
163 func (k Float64) From(l event.Label) float64 {
164 return l.Float64()
165 }
166
167 // String represents a key
168 type String string
169
170 // Of creates a new Label with this key and the supplied value.
171 func (k String) Of(v string) event.Label {
172 return event.String(string(k), v)
173 }
174
175 // From can be used to get a value from a Label.
176 func (k String) From(l event.Label) string { return l.String() }
177
178 // Bool represents a key
179 type Bool string
180
181 // Of creates a new Label with this key and the supplied value.
182 func (k Bool) Of(v bool) event.Label {
183 return event.Bool(string(k), v)
184 }
185
186 // From can be used to get a value from a Label.
187 func (k Bool) From(l event.Label) bool { return l.Bool() }
188
189 // Error represents a key
190 type Error string
191
192 // Of creates a new Label with this key and the supplied value.
193 func (k Error) Of(v error) event.Label {
194 return event.Value(string(k), v)
195 }
196
197 // From can be used to get a value from a Label.
198 func (k Error) From(l event.Label) error { return l.Interface().(error) }