Joey Armstrong | 903c69d | 2024-02-01 19:46:39 -0500 | [diff] [blame] | 1 | // Copyright The OpenTelemetry Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package label |
| 16 | |
| 17 | // Key represents the key part in key-value pairs. It's a string. The |
| 18 | // allowed character set in the key depends on the use of the key. |
| 19 | type Key string |
| 20 | |
| 21 | // Bool creates a KeyValue instance with a BOOL Value. |
| 22 | // |
| 23 | // If creating both key and a bool value at the same time, then |
| 24 | // instead of calling Key(name).Bool(value) consider using a |
| 25 | // convenience function provided by the api/key package - |
| 26 | // key.Bool(name, value). |
| 27 | func (k Key) Bool(v bool) KeyValue { |
| 28 | return KeyValue{ |
| 29 | Key: k, |
| 30 | Value: BoolValue(v), |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // Int64 creates a KeyValue instance with an INT64 Value. |
| 35 | // |
| 36 | // If creating both key and an int64 value at the same time, then |
| 37 | // instead of calling Key(name).Int64(value) consider using a |
| 38 | // convenience function provided by the api/key package - |
| 39 | // key.Int64(name, value). |
| 40 | func (k Key) Int64(v int64) KeyValue { |
| 41 | return KeyValue{ |
| 42 | Key: k, |
| 43 | Value: Int64Value(v), |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // Uint64 creates a KeyValue instance with a UINT64 Value. |
| 48 | // |
| 49 | // If creating both key and a uint64 value at the same time, then |
| 50 | // instead of calling Key(name).Uint64(value) consider using a |
| 51 | // convenience function provided by the api/key package - |
| 52 | // key.Uint64(name, value). |
| 53 | func (k Key) Uint64(v uint64) KeyValue { |
| 54 | return KeyValue{ |
| 55 | Key: k, |
| 56 | Value: Uint64Value(v), |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // Float64 creates a KeyValue instance with a FLOAT64 Value. |
| 61 | // |
| 62 | // If creating both key and a float64 value at the same time, then |
| 63 | // instead of calling Key(name).Float64(value) consider using a |
| 64 | // convenience function provided by the api/key package - |
| 65 | // key.Float64(name, value). |
| 66 | func (k Key) Float64(v float64) KeyValue { |
| 67 | return KeyValue{ |
| 68 | Key: k, |
| 69 | Value: Float64Value(v), |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // Int32 creates a KeyValue instance with an INT32 Value. |
| 74 | // |
| 75 | // If creating both key and an int32 value at the same time, then |
| 76 | // instead of calling Key(name).Int32(value) consider using a |
| 77 | // convenience function provided by the api/key package - |
| 78 | // key.Int32(name, value). |
| 79 | func (k Key) Int32(v int32) KeyValue { |
| 80 | return KeyValue{ |
| 81 | Key: k, |
| 82 | Value: Int32Value(v), |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // Uint32 creates a KeyValue instance with a UINT32 Value. |
| 87 | // |
| 88 | // If creating both key and a uint32 value at the same time, then |
| 89 | // instead of calling Key(name).Uint32(value) consider using a |
| 90 | // convenience function provided by the api/key package - |
| 91 | // key.Uint32(name, value). |
| 92 | func (k Key) Uint32(v uint32) KeyValue { |
| 93 | return KeyValue{ |
| 94 | Key: k, |
| 95 | Value: Uint32Value(v), |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // Float32 creates a KeyValue instance with a FLOAT32 Value. |
| 100 | // |
| 101 | // If creating both key and a float32 value at the same time, then |
| 102 | // instead of calling Key(name).Float32(value) consider using a |
| 103 | // convenience function provided by the api/key package - |
| 104 | // key.Float32(name, value). |
| 105 | func (k Key) Float32(v float32) KeyValue { |
| 106 | return KeyValue{ |
| 107 | Key: k, |
| 108 | Value: Float32Value(v), |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // String creates a KeyValue instance with a STRING Value. |
| 113 | // |
| 114 | // If creating both key and a string value at the same time, then |
| 115 | // instead of calling Key(name).String(value) consider using a |
| 116 | // convenience function provided by the api/key package - |
| 117 | // key.String(name, value). |
| 118 | func (k Key) String(v string) KeyValue { |
| 119 | return KeyValue{ |
| 120 | Key: k, |
| 121 | Value: StringValue(v), |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // Int creates a KeyValue instance with either an INT32 or an INT64 |
| 126 | // Value, depending on whether the int type is 32 or 64 bits wide. |
| 127 | // |
| 128 | // If creating both key and an int value at the same time, then |
| 129 | // instead of calling Key(name).Int(value) consider using a |
| 130 | // convenience function provided by the api/key package - |
| 131 | // key.Int(name, value). |
| 132 | func (k Key) Int(v int) KeyValue { |
| 133 | return KeyValue{ |
| 134 | Key: k, |
| 135 | Value: IntValue(v), |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | // Uint creates a KeyValue instance with either a UINT32 or a UINT64 |
| 140 | // Value, depending on whether the uint type is 32 or 64 bits wide. |
| 141 | // |
| 142 | // If creating both key and a uint value at the same time, then |
| 143 | // instead of calling Key(name).Uint(value) consider using a |
| 144 | // convenience function provided by the api/key package - |
| 145 | // key.Uint(name, value). |
| 146 | func (k Key) Uint(v uint) KeyValue { |
| 147 | return KeyValue{ |
| 148 | Key: k, |
| 149 | Value: UintValue(v), |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // Defined returns true for non-empty keys. |
| 154 | func (k Key) Defined() bool { |
| 155 | return len(k) != 0 |
| 156 | } |
| 157 | |
| 158 | // Array creates a KeyValue instance with a ARRAY Value. |
| 159 | // |
| 160 | // If creating both key and a array value at the same time, then |
| 161 | // instead of calling Key(name).String(value) consider using a |
| 162 | // convenience function provided by the api/key package - |
| 163 | // key.Array(name, value). |
| 164 | func (k Key) Array(v interface{}) KeyValue { |
| 165 | return KeyValue{ |
| 166 | Key: k, |
| 167 | Value: ArrayValue(v), |
| 168 | } |
| 169 | } |