restore v0.3.0

This commit is contained in:
andrey1s
2021-09-19 17:25:47 +03:00
parent f9ae79614a
commit deb67b0008
37 changed files with 3472 additions and 332 deletions

31
field/encoder.go Normal file
View File

@@ -0,0 +1,31 @@
package field
import "time"
type Encoder interface {
// Built-in types.
AddArray(key string, value Value)
AddAny(key string, value Value)
AddNil(key string)
AddBool(key string, value bool)
AddBinary(key string, value []byte)
AddInt(key string, value int)
AddInt8(key string, value int8)
AddInt16(key string, value int16)
AddInt32(key string, value int32)
AddInt64(key string, value int64)
AddUint(key string, value uint)
AddUint8(key string, value uint8)
AddUint16(key string, value uint16)
AddUint32(key string, value uint32)
AddUint64(key string, value uint64)
AddUintptr(key string, value uintptr)
AddTime(key string, value time.Time)
AddDuration(key string, value time.Duration)
AddFloat32(key string, value float32)
AddFloat64(key string, value float64)
AddComplex64(key string, value complex64)
AddComplex128(key string, value complex128)
AddString(key, value string)
AddError(key string, value error)
}

333
field/field.go Normal file
View File

@@ -0,0 +1,333 @@
package field
import (
"fmt"
"time"
)
func Any(key string, value interface{}) Field {
return Key(key).Any(value)
}
func String(key, value string) Field {
return Key(key).String(value)
}
func Stringp(key string, value *string) Field {
return Key(key).Stringp(value)
}
func Strings(key string, value ...string) Field {
return Key(key).Strings(value...)
}
func Bool(key string, value bool) Field {
return Key(key).Bool(value)
}
func Bools(key string, value ...bool) Field {
return Key(key).Bools(value...)
}
func Boolp(key string, value *bool) Field {
return Key(key).Boolp(value)
}
func Uint(key string, value uint) Field {
return Key(key).Uint(value)
}
func Uints(key string, value ...uint) Field {
return Key(key).Uints(value...)
}
func Uintp(key string, value *uint) Field {
return Key(key).Uintp(value)
}
func Uint8(key string, value uint8) Field {
return Key(key).Uint8(value)
}
func Uint8s(key string, value ...uint8) Field {
return Key(key).Uint8s(value...)
}
func Uint8p(key string, value *uint8) Field {
return Key(key).Uint8p(value)
}
func Uint16(key string, value uint16) Field {
return Key(key).Uint16(value)
}
func Uint16s(key string, value ...uint16) Field {
return Key(key).Uint16s(value...)
}
func Uint16p(key string, value *uint16) Field {
return Key(key).Uint16p(value)
}
func Uint32(key string, value uint32) Field {
return Key(key).Uint32(value)
}
func Uint32s(key string, value ...uint32) Field {
return Key(key).Uint32s(value...)
}
func Uint32p(key string, value *uint32) Field {
return Key(key).Uint32p(value)
}
func Uint64(key string, value uint64) Field {
return Key(key).Uint64(value)
}
func Uint64s(key string, value ...uint64) Field {
return Key(key).Uint64s(value...)
}
func Uint64p(key string, value *uint64) Field {
return Key(key).Uint64p(value)
}
func Int(key string, value int) Field {
return Key(key).Int(value)
}
func Ints(key string, value ...int) Field {
return Key(key).Ints(value...)
}
func Intp(key string, value *int) Field {
return Key(key).Intp(value)
}
func Int8(key string, value int8) Field {
return Key(key).Int8(value)
}
func Int8s(key string, value ...int8) Field {
return Key(key).Int8s(value...)
}
func Int8p(key string, value *int8) Field {
return Key(key).Int8p(value)
}
func Int16(key string, value int16) Field {
return Key(key).Int16(value)
}
func Int16s(key string, value ...int16) Field {
return Key(key).Int16s(value...)
}
func Int16p(key string, value *int16) Field {
return Key(key).Int16p(value)
}
func Int32(key string, value int32) Field {
return Key(key).Int32(value)
}
func Int32s(key string, value ...int32) Field {
return Key(key).Int32s(value...)
}
func Int32p(key string, value *int32) Field {
return Key(key).Int32p(value)
}
func Int64(key string, value int64) Field {
return Key(key).Int64(value)
}
func Int64s(key string, value ...int64) Field {
return Key(key).Int64s(value...)
}
func Int64p(key string, value *int64) Field {
return Key(key).Int64p(value)
}
func Float32(key string, value float32) Field {
return Key(key).Float32(value)
}
func Float32s(key string, value ...float32) Field {
return Key(key).Float32s(value...)
}
func Float32p(key string, value *float32) Field {
return Key(key).Float32p(value)
}
func Float64(key string, value float64) Field {
return Key(key).Float64(value)
}
func Float64s(key string, value ...float64) Field {
return Key(key).Float64s(value...)
}
func Float64p(key string, value *float64) Field {
return Key(key).Float64p(value)
}
func Complex64(key string, value complex64) Field {
return Key(key).Complex64(value)
}
func Complex64s(key string, value ...complex64) Field {
return Key(key).Complex64s(value...)
}
func Complex64p(key string, value *complex64) Field {
return Key(key).Complex64p(value)
}
func Uintptr(key string, value uintptr) Field {
return Key(key).Uintptr(value)
}
func Uintptrs(key string, value ...uintptr) Field {
return Key(key).Uintptrs(value...)
}
func Uintptrp(key string, value *uintptr) Field {
return Key(key).Uintptrp(value)
}
func Bytes(key string, value []byte) Field {
return Key(key).Bytes(value)
}
func Duration(key string, value time.Duration) Field {
return Key(key).Dureation(value)
}
func Durations(key string, value ...time.Duration) Field {
return Key(key).Dureations(value)
}
func Durationp(key string, value *time.Duration) Field {
return Key(key).Dureationp(value)
}
func Time(key string, value time.Time) Field {
return Key(key).Time(value)
}
func Times(key string, value ...time.Time) Field {
return Key(key).Times(value...)
}
func Timep(key string, value *time.Time) Field {
return Key(key).Timep(value)
}
func FormatTime(key, format string, value time.Time) Field {
return Key(key).FormatTime(format, value)
}
func FormatTimes(key, foramt string, value ...time.Time) Field {
return Key(key).FormatTimes(foramt, value...)
}
func FormatTimep(key, foramt string, value *time.Time) Field {
return Key(key).FormatTimep(foramt, value)
}
func Error(key string, value error) Field {
return Key(key).Error(value)
}
func Errors(key string, value ...error) Field {
return Key(key).Errors(value...)
}
// Field struct.
type Field struct {
key Key
value Value
}
//nolint: gocyclo
func (f Field) AddTo(enc Encoder) {
key := string(f.key)
switch {
case f.value.IsArray():
enc.AddAny(key, f.value)
case f.value.IsNil():
enc.AddNil(key)
case f.value.IsBool():
enc.AddBool(key, f.value.asBool())
case f.value.IsBinary():
enc.AddBinary(key, f.value.asBinary())
case f.value.IsInt():
enc.AddInt(key, f.value.asInt())
case f.value.IsInt8():
enc.AddInt8(key, f.value.asInt8())
case f.value.IsInt16():
enc.AddInt16(key, f.value.asInt16())
case f.value.IsInt32():
enc.AddInt32(key, f.value.asInt32())
case f.value.IsInt64():
enc.AddInt64(key, f.value.asInt64())
case f.value.IsUint():
enc.AddUint(key, f.value.asUint())
case f.value.IsUint8():
enc.AddUint8(key, f.value.asUint8())
case f.value.IsUint16():
enc.AddUint16(key, f.value.asUint16())
case f.value.IsUint32():
enc.AddUint32(key, f.value.asUint32())
case f.value.IsUint64():
enc.AddUint64(key, f.value.asUint64())
case f.value.IsUintptr():
enc.AddUintptr(key, f.value.asUintptr())
case f.value.IsTime():
enc.AddTime(key, f.value.asTime())
case f.value.IsDuration():
enc.AddDuration(key, f.value.asDuration())
case f.value.IsFloat32():
enc.AddFloat32(key, f.value.asFloat32())
case f.value.IsFloat64():
enc.AddFloat64(key, f.value.asFloat64())
case f.value.IsComplex64():
enc.AddComplex64(key, f.value.asComplex64())
case f.value.IsComplex128():
enc.AddComplex128(key, f.value.asComplex128())
case f.value.IsString():
enc.AddString(key, f.value.asString())
case f.value.IsError():
enc.AddError(key, f.value.asError())
default:
enc.AddAny(key, f.value)
}
}
func (f Field) Type() Type {
return f.value.vtype
}
func (f Field) Key() Key {
return f.key
}
func (f Field) Value() Value {
return f.value
}
func (f Field) AsInterface() interface{} {
return f.value.AsInterface()
}
// String implent stringer.
func (f Field) String() string {
return fmt.Sprintf("%s=%+v", f.key, f.value.AsInterface())
}

29
field/fields.go Normal file
View File

@@ -0,0 +1,29 @@
package field
type Fields []Field
type MapField map[Key]Value
func (f Fields) Append(fields ...Field) Fields {
f = append(f, fields...)
return f
}
func (f Fields) Set(idx int, field Field) {
f[idx] = field
}
func (f Fields) Len() int {
return len(f)
}
func (f Fields) AsMap() MapField {
m := make(MapField, len(f))
for _, field := range f {
m[field.Key()] = field.Value()
}
return m
}

568
field/key.go Normal file
View File

@@ -0,0 +1,568 @@
package field
import (
"time"
)
type Key string
//nolint: gocyclo, funlen
func (k Key) Any(value interface{}) Field {
switch v := value.(type) {
case string:
return k.String(v)
case *string:
return k.Stringp(v)
case []string:
return k.Strings(v...)
case bool:
return k.Bool(v)
case *bool:
return k.Boolp(v)
case []bool:
return k.Bools(v...)
case int8:
return k.Int8(v)
case []int8:
return k.Int8s(v...)
case *int8:
return k.Int8p(v)
case int16:
return k.Int16(v)
case []int16:
return k.Int16s(v...)
case *int16:
return k.Int16p(v)
case int32:
return k.Int32(v)
case []int32:
return k.Int32s(v...)
case *int32:
return k.Int32p(v)
case int64:
return k.Int64(v)
case []int64:
return k.Int64s(v...)
case *int64:
return k.Int64p(v)
case uint:
return k.Uint(v)
case []uint:
return k.Uints(v...)
case *uint:
return k.Uintp(v)
case uint8:
return k.Uint8(v)
case *uint8:
return k.Uint8p(v)
case uint16:
return k.Uint16(v)
case []uint16:
return k.Uint16s(v...)
case *uint16:
return k.Uint16p(v)
case uint32:
return k.Uint32(v)
case []uint32:
return k.Uint32s(v...)
case *uint32:
return k.Uint32p(v)
case uint64:
return k.Uint64(v)
case []uint64:
return k.Uint64s(v...)
case *uint64:
return k.Uint64p(v)
case float32:
return k.Float32(v)
case []float32:
return k.Float32s(v...)
case *float32:
return k.Float32p(v)
case float64:
return k.Float64(v)
case []float64:
return k.Float64s(v...)
case *float64:
return k.Float64p(v)
case complex64:
return k.Complex64(v)
case []complex64:
return k.Complex64s(v...)
case *complex64:
return k.Complex64p(v)
case uintptr:
return k.Uintptr(v)
case []uintptr:
return k.Uintptrs(v...)
case *uintptr:
return k.Uintptrp(v)
case []byte:
return k.Bytes(v)
case time.Duration:
return k.Dureation(v)
case []time.Duration:
return k.Dureations(v)
case *time.Duration:
return k.Dureationp(v)
case time.Time:
return k.Time(v)
case []time.Time:
return k.Times(v...)
case *time.Time:
return k.Timep(v)
case error:
return k.Error(v)
case []error:
return k.Errors(v...)
}
return Field{
key: k,
value: Value{
value: value,
vtype: TypeAny,
},
}
}
func (k Key) String(value string) Field {
return Field{
key: k,
value: stringValue(value),
}
}
func (k Key) Strings(value ...string) Field {
return Field{
key: k,
value: stringsValue(value),
}
}
func (k Key) Stringp(value *string) Field {
return Field{
key: k,
value: stringpValue(value),
}
}
func (k Key) Bool(value bool) Field {
return Field{
key: k,
value: boolValue(value),
}
}
func (k Key) Bools(value ...bool) Field {
return Field{
key: k,
value: boolsValue(value),
}
}
func (k Key) Boolp(value *bool) Field {
return Field{
key: k,
value: boolpValue(value),
}
}
func (k Key) Int(value int) Field {
return Field{
key: k,
value: intValue(value),
}
}
func (k Key) Ints(value ...int) Field {
return Field{
key: k,
value: intsValue(value),
}
}
func (k Key) Intp(value *int) Field {
return Field{
key: k,
value: intpValue(value),
}
}
func (k Key) Int8(value int8) Field {
return Field{
key: k,
value: int8Value(value),
}
}
func (k Key) Int8s(value ...int8) Field {
return Field{
key: k,
value: int8sValue(value),
}
}
func (k Key) Int8p(value *int8) Field {
return Field{
key: k,
value: int8pValue(value),
}
}
func (k Key) Int16(value int16) Field {
return Field{
key: k,
value: int16Value(value),
}
}
func (k Key) Int16s(value ...int16) Field {
return Field{
key: k,
value: int16sValue(value),
}
}
func (k Key) Int16p(value *int16) Field {
return Field{
key: k,
value: int16pValue(value),
}
}
func (k Key) Int32(value int32) Field {
return Field{
key: k,
value: int32Value(value),
}
}
func (k Key) Int32s(value ...int32) Field {
return Field{
key: k,
value: int32sValue(value),
}
}
func (k Key) Int32p(value *int32) Field {
return Field{
key: k,
value: int32pValue(value),
}
}
func (k Key) Int64(value int64) Field {
return Field{
key: k,
value: int64Value(value),
}
}
func (k Key) Int64s(value ...int64) Field {
return Field{
key: k,
value: int64sValue(value),
}
}
func (k Key) Int64p(value *int64) Field {
return Field{
key: k,
value: int64pValue(value),
}
}
func (k Key) Uint(value uint) Field {
return Field{
key: k,
value: uintValue(value),
}
}
func (k Key) Uints(value ...uint) Field {
return Field{
key: k,
value: uintsValue(value),
}
}
func (k Key) Uintp(value *uint) Field {
return Field{
key: k,
value: uintpValue(value),
}
}
func (k Key) Uint8(value uint8) Field {
return Field{
key: k,
value: uint8Value(value),
}
}
func (k Key) Uint8s(value ...uint8) Field {
return Field{
key: k,
value: uint8sValue(value),
}
}
func (k Key) Uint8p(value *uint8) Field {
return Field{
key: k,
value: uint8pValue(value),
}
}
func (k Key) Uint16(value uint16) Field {
return Field{
key: k,
value: uint16Value(value),
}
}
func (k Key) Uint16s(value ...uint16) Field {
return Field{
key: k,
value: uint16sValue(value),
}
}
func (k Key) Uint16p(value *uint16) Field {
return Field{
key: k,
value: uint16pValue(value),
}
}
func (k Key) Uint32(value uint32) Field {
return Field{
key: k,
value: uint32Value(value),
}
}
func (k Key) Uint32s(value ...uint32) Field {
return Field{
key: k,
value: uint32sValue(value),
}
}
func (k Key) Uint32p(value *uint32) Field {
return Field{
key: k,
value: uint32pValue(value),
}
}
func (k Key) Uint64(value uint64) Field {
return Field{
key: k,
value: uint64Value(value),
}
}
func (k Key) Uint64s(value ...uint64) Field {
return Field{
key: k,
value: uint64sValue(value),
}
}
func (k Key) Uint64p(value *uint64) Field {
return Field{
key: k,
value: uint64pValue(value),
}
}
func (k Key) Float32(value float32) Field {
return Field{
key: k,
value: float32Value(value),
}
}
func (k Key) Float32s(value ...float32) Field {
return Field{
key: k,
value: float32sValue(value),
}
}
func (k Key) Float32p(value *float32) Field {
return Field{
key: k,
value: float32pValue(value),
}
}
func (k Key) Float64(value float64) Field {
return Field{
key: k,
value: float64Value(value),
}
}
func (k Key) Float64s(value ...float64) Field {
return Field{
key: k,
value: float64sValue(value),
}
}
func (k Key) Float64p(value *float64) Field {
return Field{
key: k,
value: float64pValue(value),
}
}
func (k Key) Complex64(value complex64) Field {
return Field{
key: k,
value: complex64Value(value),
}
}
func (k Key) Complex64s(value ...complex64) Field {
return Field{
key: k,
value: complex64sValue(value),
}
}
func (k Key) Complex64p(value *complex64) Field {
return Field{
key: k,
value: complex64pValue(value),
}
}
func (k Key) Complex128(value complex128) Field {
return Field{
key: k,
value: complex128Value(value),
}
}
func (k Key) Complex128s(value []complex128) Field {
return Field{
key: k,
value: complex128sValue(value),
}
}
func (k Key) Complex128p(value *complex128) Field {
return Field{
key: k,
value: complex128pValue(value),
}
}
func (k Key) Uintptr(value uintptr) Field {
return Field{
key: k,
value: uintptrValue(value),
}
}
func (k Key) Uintptrs(value ...uintptr) Field {
return Field{
key: k,
value: uintptrsValue(value),
}
}
func (k Key) Uintptrp(value *uintptr) Field {
return Field{
key: k,
value: uintptrpValue(value),
}
}
func (k Key) Bytes(value []byte) Field {
return Field{
key: k,
value: bytesValue(value),
}
}
func (k Key) Dureation(value time.Duration) Field {
return Field{
key: k,
value: durationValue(value),
}
}
func (k Key) Dureations(value []time.Duration) Field {
return Field{
key: k,
value: durationsValue(value),
}
}
func (k Key) Dureationp(value *time.Duration) Field {
return Field{
key: k,
value: durationpValue(value),
}
}
func (k Key) Time(value time.Time) Field {
return Field{
key: k,
value: timeValue(value),
}
}
func (k Key) Times(value ...time.Time) Field {
return Field{
key: k,
value: timesValue(value),
}
}
func (k Key) Timep(value *time.Time) Field {
return Field{
key: k,
value: timepValue(value),
}
}
func (k Key) FormatTime(format string, value time.Time) Field {
return Field{
key: k,
value: formatTimeValue(format, value),
}
}
func (k Key) FormatTimes(format string, value ...time.Time) Field {
return Field{
key: k,
value: formatTimesValue(format, value),
}
}
func (k Key) FormatTimep(format string, value *time.Time) Field {
return Field{
key: k,
value: formatTimepValue(format, value),
}
}
func (k Key) Error(value error) Field {
return Field{
key: k,
value: errorValue(value),
}
}
func (k Key) Errors(value ...error) Field {
return Field{
key: k,
value: errorsValue(value),
}
}

126
field/type.go Normal file
View File

@@ -0,0 +1,126 @@
package field
type Type uint32
const (
TypeAny Type = 1 << iota // any
TypeArray // array
TypeNil // nil
TypeString // string
TypeBool // bool
TypeInt // int
TypeInt8 // int8
TypeInt16 // int16
TypeInt32 // int32
TypeInt64 // int64
TypeUint // uint
TypeUint8 // uint8
TypeUint16 // uint16
TypeUint32 // uint32
TypeUint64 // uint64
TypeFloat32 // float32
TypeFloat64 // float64
TypeComplex64 // complex64
TypeComplex128 // complex128
TypeUintptr // uintptr
TypeBinary // bytes
TypeDuration // duration
TypeTime // time
TypeError // error
)
func (t Type) IsAny() bool {
return t&TypeAny > 0
}
func (t Type) IsArray() bool {
return t&TypeArray > 0
}
func (t Type) IsNil() bool {
return t&TypeNil > 0
}
func (t Type) IsBool() bool {
return t&TypeBool > 0
}
func (t Type) IsString() bool {
return t&TypeString > 0
}
func (t Type) IsInt() bool {
return t&TypeInt > 0
}
func (t Type) IsInt8() bool {
return t&TypeInt8 > 0
}
func (t Type) IsInt16() bool {
return t&TypeInt16 > 0
}
func (t Type) IsInt32() bool {
return t&TypeInt32 > 0
}
func (t Type) IsInt64() bool {
return t&TypeInt64 > 0
}
func (t Type) IsUint() bool {
return t&TypeUint > 0
}
func (t Type) IsUint8() bool {
return t&TypeUint8 > 0
}
func (t Type) IsUint16() bool {
return t&TypeUint16 > 0
}
func (t Type) IsUint32() bool {
return t&TypeUint32 > 0
}
func (t Type) IsUint64() bool {
return t&TypeUint64 > 0
}
func (t Type) IsFloat32() bool {
return t&TypeFloat32 > 0
}
func (t Type) IsFloat64() bool {
return t&TypeFloat64 > 0
}
func (t Type) IsComplex64() bool {
return t&TypeComplex64 > 0
}
func (t Type) IsComplex128() bool {
return t&TypeComplex128 > 0
}
func (t Type) IsUintptr() bool {
return t&TypeUintptr > 0
}
func (t Type) IsBinary() bool {
return t&TypeBinary > 0
}
func (t Type) IsDuration() bool {
return t&TypeDuration > 0
}
func (t Type) IsTime() bool {
return t&TypeTime > 0
}
func (t Type) IsError() bool {
return t&TypeError > 0
}

755
field/value.go Normal file
View File

@@ -0,0 +1,755 @@
package field
import (
"encoding/json"
"fmt"
"math"
"strconv"
"time"
)
type Value struct {
vtype Type
numeric uint64
stringly string
value interface{}
}
func (v Value) MarshalJSON() ([]byte, error) {
return json.Marshal(v.AsInterface())
}
//nolint: gocyclo
func (v Value) String() string {
switch {
case v.vtype.IsArray(), v.vtype.IsAny():
return fmt.Sprintf("%+v", v.AsInterface())
case v.vtype.IsNil():
return "<nil>"
case v.vtype.IsString():
return v.asString()
case v.vtype.IsBool():
return strconv.FormatBool(v.asBool())
case v.vtype.IsInt(), v.vtype.IsInt8(), v.vtype.IsInt16(), v.vtype.IsInt32():
return strconv.Itoa(v.asInt())
case v.vtype.IsInt64():
return strconv.FormatInt(v.asInt64(), 10)
case v.vtype.IsUint(), v.vtype.IsUint8(), v.vtype.IsUint16(), v.vtype.IsUint32(), v.vtype.IsUint64():
return strconv.FormatUint(v.asUint64(), 10)
case v.vtype.IsFloat64():
return strconv.FormatFloat(v.asFloat64(), 'g', -1, 64)
case v.vtype.IsFloat32():
return strconv.FormatFloat(float64(v.asFloat32()), 'g', -1, 32)
case v.vtype.IsComplex128():
return strconv.FormatComplex(v.asComplex128(), 'g', -1, 128)
case v.vtype.IsComplex64():
return strconv.FormatComplex(complex128(v.asComplex64()), 'g', -1, 64)
case v.vtype.IsBinary():
return string(v.asBinary())
case v.vtype.IsDuration():
return v.asDuration().String()
case v.vtype.IsTime():
return v.asTime().Format(v.asString())
case v.vtype.IsError():
return v.asError().Error()
}
return fmt.Sprintf("%+v", v.AsInterface())
}
//nolint: gocyclo
func (v Value) AsInterface() interface{} {
switch {
case v.vtype.IsArray():
return v.value
case v.vtype.IsNil():
return nil
case v.vtype.IsString():
return v.asString()
case v.vtype.IsBool():
return v.asBool()
case v.vtype.IsInt():
return v.asInt()
case v.vtype.IsInt8():
return v.asInt8()
case v.vtype.IsInt16():
return v.asInt16()
case v.vtype.IsInt32():
return v.asInt32()
case v.vtype.IsInt64():
return v.asInt64()
case v.vtype.IsUint():
return v.asUint()
case v.vtype.IsUint8():
return v.asUint8()
case v.vtype.IsUint16():
return v.asUint16()
case v.vtype.IsUint32():
return v.asUint32()
case v.vtype.IsUint64():
return v.asUint64()
case v.vtype.IsFloat32():
return v.asFloat32()
case v.vtype.IsFloat64():
return v.asFloat64()
case v.vtype.IsComplex64():
return v.asComplex64()
case v.vtype.IsComplex128():
return v.asComplex128()
case v.vtype.IsUintptr():
return v.asUintptr()
case v.vtype.IsBinary():
return v.asBinary()
case v.vtype.IsDuration():
return v.asDuration()
case v.vtype.IsTime():
return v.asTime()
case v.vtype.IsError():
return v.asError()
}
return v.value
}
func (v Value) IsArray() bool {
return v.vtype.IsArray()
}
func (v Value) IsNil() bool {
return v.vtype.IsNil()
}
func (v Value) IsString() bool {
return v.vtype.IsString()
}
func (v Value) IsBool() bool {
return v.vtype.IsBool()
}
func (v Value) IsInt() bool {
return v.vtype.IsInt()
}
func (v Value) IsInt8() bool {
return v.vtype.IsInt8()
}
func (v Value) IsInt16() bool {
return v.vtype.IsInt16()
}
func (v Value) IsInt32() bool {
return v.vtype.IsInt32()
}
func (v Value) IsInt64() bool {
return v.vtype.IsInt64()
}
func (v Value) IsUint() bool {
return v.vtype.IsUint()
}
func (v Value) IsUint8() bool {
return v.vtype.IsUint8()
}
func (v Value) IsUint16() bool {
return v.vtype.IsUint16()
}
func (v Value) IsUint32() bool {
return v.vtype.IsUint32()
}
func (v Value) IsUint64() bool {
return v.vtype.IsUint64()
}
func (v Value) IsFloat32() bool {
return v.vtype.IsFloat32()
}
func (v Value) IsFloat64() bool {
return v.vtype.IsFloat64()
}
func (v Value) IsComplex64() bool {
return v.vtype.IsComplex64()
}
func (v Value) IsComplex128() bool {
return v.vtype.IsComplex128()
}
func (v Value) IsUintptr() bool {
return v.vtype.IsUintptr()
}
func (v Value) IsBinary() bool {
return v.vtype.IsBinary()
}
func (v Value) IsDuration() bool {
return v.vtype.IsDuration()
}
func (v Value) IsTime() bool {
return v.vtype.IsTime()
}
func (v Value) IsError() bool {
return v.vtype.IsError()
}
func (v Value) asString() string {
return v.stringly
}
func (v Value) asBool() bool {
return v.numeric == 1
}
func (v Value) asInt() int {
return int(v.numeric)
}
func (v Value) asInt8() int8 {
return int8(v.numeric)
}
func (v Value) asInt16() int16 {
return int16(v.numeric)
}
func (v Value) asInt32() int32 {
return int32(v.numeric)
}
func (v Value) asInt64() int64 {
return int64(v.numeric)
}
func (v Value) asUint() uint {
return uint(v.numeric)
}
func (v Value) asUint8() uint8 {
return uint8(v.numeric)
}
func (v Value) asUint16() uint16 {
return uint16(v.numeric)
}
func (v Value) asUint32() uint32 {
return uint32(v.numeric)
}
func (v Value) asUint64() uint64 {
return v.numeric
}
func (v Value) asFloat32() float32 {
return math.Float32frombits(uint32(v.numeric))
}
func (v Value) asFloat64() float64 {
return math.Float64frombits(v.numeric)
}
func (v Value) asComplex64() complex64 {
return v.value.(complex64)
}
func (v Value) asComplex128() complex128 {
return v.value.(complex128)
}
func (v Value) asUintptr() uintptr {
return v.value.(uintptr)
}
func (v Value) asBinary() []byte {
return v.value.([]byte)
}
func (v Value) asDuration() time.Duration {
return v.value.(time.Duration)
}
func (v Value) asTime() time.Time {
return v.value.(time.Time)
}
func (v Value) asError() error {
return v.value.(error)
}
func nilValue(t Type) Value {
return Value{vtype: t | TypeNil}
}
func stringValue(v string) Value {
return Value{
stringly: v,
vtype: TypeString,
}
}
func stringsValue(v []string) Value {
return Value{
value: v,
vtype: TypeString | TypeArray,
}
}
func stringpValue(v *string) Value {
if v != nil {
return stringValue(*v)
}
return nilValue(TypeString)
}
func boolValue(b bool) Value {
if b {
return Value{
numeric: 1,
vtype: TypeBool,
}
}
return Value{
vtype: TypeBool,
}
}
func boolsValue(b []bool) Value {
return Value{
value: b,
vtype: TypeBool | TypeArray,
}
}
func boolpValue(b *bool) Value {
if b != nil {
return boolValue(*b)
}
return nilValue(TypeBool)
}
func intValue(i int) Value {
return Value{
vtype: TypeInt,
numeric: uint64(i),
}
}
func intsValue(i []int) Value {
return Value{
value: i,
vtype: TypeInt | TypeArray,
}
}
func intpValue(in *int) Value {
if in != nil {
return intValue(*in)
}
return nilValue(TypeInt)
}
func int8Value(i int8) Value {
return Value{
vtype: TypeInt8,
numeric: uint64(i),
}
}
func int8sValue(i []int8) Value {
return Value{
value: i,
vtype: TypeInt8 | TypeArray,
}
}
func int8pValue(in *int8) Value {
if in != nil {
return int8Value(*in)
}
return nilValue(TypeInt8)
}
func int16Value(i int16) Value {
return Value{
vtype: TypeInt16,
numeric: uint64(i),
}
}
func int16sValue(i []int16) Value {
return Value{
value: i,
vtype: TypeInt16 | TypeArray,
}
}
func int16pValue(in *int16) Value {
if in != nil {
return int16Value(*in)
}
return nilValue(TypeInt16)
}
func int32Value(i int32) Value {
return Value{
vtype: TypeInt32,
numeric: uint64(i),
}
}
func int32sValue(i []int32) Value {
return Value{
value: i,
vtype: TypeInt32 | TypeArray,
}
}
func int32pValue(in *int32) Value {
if in != nil {
return int32Value(*in)
}
return nilValue(TypeInt32)
}
func int64Value(i int64) Value {
return Value{
vtype: TypeInt64,
numeric: uint64(i),
}
}
func int64sValue(i []int64) Value {
return Value{
value: i,
vtype: TypeInt64 | TypeArray,
}
}
func int64pValue(in *int64) Value {
if in != nil {
return int64Value(*in)
}
return nilValue(TypeInt64)
}
func uintValue(i uint) Value {
return Value{
vtype: TypeUint,
numeric: uint64(i),
}
}
func uintsValue(i []uint) Value {
return Value{
value: i,
vtype: TypeUint | TypeArray,
}
}
func uintpValue(in *uint) Value {
if in != nil {
return uintValue(*in)
}
return nilValue(TypeUint)
}
func uint8Value(i uint8) Value {
return Value{
vtype: TypeUint8,
numeric: uint64(i),
}
}
func uint8sValue(i []uint8) Value {
return Value{
value: i,
vtype: TypeUint8 | TypeArray,
}
}
func uint8pValue(in *uint8) Value {
if in != nil {
return uint8Value(*in)
}
return nilValue(TypeUint8)
}
func uint16Value(i uint16) Value {
return Value{
vtype: TypeUint16,
numeric: uint64(i),
}
}
func uint16sValue(i []uint16) Value {
return Value{
value: i,
vtype: TypeUint16 | TypeArray,
}
}
func uint16pValue(in *uint16) Value {
if in != nil {
return uint16Value(*in)
}
return nilValue(TypeUint16)
}
func uint32Value(i uint32) Value {
return Value{
vtype: TypeUint32,
numeric: uint64(i),
}
}
func uint32sValue(i []uint32) Value {
return Value{
value: i,
vtype: TypeUint32 | TypeArray,
}
}
func uint32pValue(in *uint32) Value {
if in != nil {
return uint32Value(*in)
}
return nilValue(TypeUint32)
}
func uint64Value(i uint64) Value {
return Value{
vtype: TypeUint64,
numeric: i,
}
}
func uint64sValue(i []uint64) Value {
return Value{
value: i,
vtype: TypeUint64 | TypeArray,
}
}
func uint64pValue(in *uint64) Value {
if in != nil {
return uint64Value(*in)
}
return nilValue(TypeUint64)
}
func float32Value(i float32) Value {
return Value{
vtype: TypeFloat32,
numeric: uint64(math.Float32bits(i)),
}
}
func float32sValue(i []float32) Value {
return Value{
value: i,
vtype: TypeFloat32 | TypeArray,
}
}
func float32pValue(in *float32) Value {
if in != nil {
return float32Value(*in)
}
return nilValue(TypeFloat32)
}
func float64Value(i float64) Value {
return Value{
vtype: TypeFloat64,
numeric: math.Float64bits(i),
}
}
func float64sValue(i []float64) Value {
return Value{
value: i,
vtype: TypeFloat64 | TypeArray,
}
}
func float64pValue(in *float64) Value {
if in != nil {
return float64Value(*in)
}
return nilValue(TypeFloat64)
}
func complex64Value(in complex64) Value {
return Value{
vtype: TypeComplex64,
value: in,
}
}
func complex64sValue(in []complex64) Value {
return Value{
vtype: TypeComplex64 | TypeArray,
value: in,
}
}
func complex64pValue(in *complex64) Value {
if in != nil {
return complex64Value(*in)
}
return nilValue(TypeComplex64)
}
func complex128Value(in complex128) Value {
return Value{
vtype: TypeComplex64,
value: in,
}
}
func complex128sValue(in []complex128) Value {
return Value{
vtype: TypeComplex128 | TypeArray,
value: in,
}
}
func complex128pValue(in *complex128) Value {
if in != nil {
return complex128Value(*in)
}
return nilValue(TypeComplex128)
}
func uintptrValue(in uintptr) Value {
return Value{
vtype: TypeUintptr,
value: in,
}
}
func uintptrsValue(in []uintptr) Value {
return Value{
vtype: TypeUintptr | TypeArray,
value: in,
}
}
func uintptrpValue(in *uintptr) Value {
if in != nil {
return uintptrValue(*in)
}
return nilValue(TypeUintptr)
}
func bytesValue(in []byte) Value {
return Value{
vtype: TypeBinary,
value: in,
}
}
func durationValue(in time.Duration) Value {
return Value{
vtype: TypeDuration,
value: in,
}
}
func durationsValue(in []time.Duration) Value {
return Value{
vtype: TypeDuration | TypeArray,
value: in,
}
}
func durationpValue(in *time.Duration) Value {
if in != nil {
return durationValue(*in)
}
return nilValue(TypeDuration)
}
func timeValue(in time.Time) Value {
return formatTimeValue(time.RFC3339, in)
}
func timesValue(in []time.Time) Value {
return formatTimesValue(time.RFC3339, in)
}
func timepValue(in *time.Time) Value {
return formatTimepValue(time.RFC3339, in)
}
func formatTimeValue(format string, in time.Time) Value {
return Value{
vtype: TypeTime,
value: in,
stringly: format,
}
}
func formatTimesValue(format string, in []time.Time) Value {
return Value{
vtype: TypeTime | TypeArray,
value: in,
stringly: format,
}
}
func formatTimepValue(format string, in *time.Time) Value {
if in != nil {
return formatTimeValue(format, *in)
}
return nilValue(TypeTime)
}
func errorValue(in error) Value {
if in != nil {
return Value{
vtype: TypeError,
value: in,
}
}
return nilValue(TypeError)
}
func errorsValue(in []error) Value {
return Value{
vtype: TypeError | TypeArray,
value: in,
}
}