move kv to label

This commit is contained in:
2020-11-01 11:36:48 +03:00
parent 50183d8ae2
commit 4f91a55f2f
9 changed files with 28 additions and 22 deletions

59
output/label/key.go Normal file
View File

@@ -0,0 +1,59 @@
package label
type Key string
func (k Key) Any(v interface{}) KeyValue {
return KeyValue{
Key: k,
Value: AnyValue(v),
}
}
func (k Key) Bool(v bool) KeyValue {
return KeyValue{
Key: k,
Value: BoolValue(v),
}
}
func (k Key) Int(v int) KeyValue {
return KeyValue{
Key: k,
Value: IntValue(v),
}
}
func (k Key) Int64(v int64) KeyValue {
return KeyValue{
Key: k,
Value: Int64Value(v),
}
}
func (k Key) Uint(v uint) KeyValue {
return KeyValue{
Key: k,
Value: UintValue(v),
}
}
func (k Key) Uint64(v uint64) KeyValue {
return KeyValue{
Key: k,
Value: Uint64Value(v),
}
}
func (k Key) Float64(v float64) KeyValue {
return KeyValue{
Key: k,
Value: Float64Value(v),
}
}
func (k Key) String(v string) KeyValue {
return KeyValue{
Key: k,
Value: StringValue(v),
}
}

63
output/label/kv.go Normal file
View File

@@ -0,0 +1,63 @@
package label
import (
"fmt"
"strings"
)
var (
_ fmt.Stringer = KeyValue{}
_ fmt.Stringer = KeyValues{}
)
type KeyValues []KeyValue
func (kv KeyValues) String() string {
s := make([]string, len(kv))
for i, v := range kv {
s[i] = v.String()
}
return strings.Join(s, ", ")
}
type KeyValue struct {
Key Key
Value Value
}
func (k KeyValue) String() string {
return string(k.Key) + "=\"" + k.Value.String() + "\""
}
func Any(k string, v interface{}) KeyValue {
return Key(k).Any(v)
}
func Bool(k string, v bool) KeyValue {
return Key(k).Bool(v)
}
func Int(k string, v int) KeyValue {
return Key(k).Int(v)
}
func Int64(k string, v int64) KeyValue {
return Key(k).Int64(v)
}
func Uint(k string, v uint) KeyValue {
return Key(k).Uint(v)
}
func Uint64(k string, v uint64) KeyValue {
return Key(k).Uint64(v)
}
func Float64(k string, v float64) KeyValue {
return Key(k).Float64(v)
}
func String(k string, v string) KeyValue {
return Key(k).String(v)
}

57
output/label/value.go Normal file
View File

@@ -0,0 +1,57 @@
package label
import "fmt"
type Type int
const (
TypeAny Type = iota
TypeBool
TypeInt
TypeInt64
TypeUint
TypeUint64
TypeFloat64
TypeString
)
type Value struct {
vtype Type
value interface{}
}
func (v Value) String() string {
return fmt.Sprint(v.value)
}
func AnyValue(v interface{}) Value {
return Value{vtype: TypeAny, value: v}
}
func BoolValue(v bool) Value {
return Value{vtype: TypeBool, value: v}
}
func IntValue(v int) Value {
return Value{vtype: TypeInt, value: v}
}
func Int64Value(v int64) Value {
return Value{vtype: TypeInt64, value: v}
}
func UintValue(v uint) Value {
return Value{vtype: TypeUint, value: v}
}
func Uint64Value(v uint64) Value {
return Value{vtype: TypeUint64, value: v}
}
func Float64Value(v float64) Value {
return Value{vtype: TypeFloat64, value: v}
}
func StringValue(v string) Value {
return Value{vtype: TypeString, value: v}
}