|
|
// ------------------------------------------------------------------------
|
|
|
// ℹ️ Project active3
|
|
|
// 🔗 Active Thing (activething.com) git.activething.com/go
|
|
|
//
|
|
|
// File name active.go
|
|
|
// ✍️ Created by DEV
|
|
|
// 📅 Modified 01/05/2024
|
|
|
//
|
|
|
// 🔒 COPYRIGHT Copyright 2024 activething.com
|
|
|
//
|
|
|
// 📜 LICENSE
|
|
|
// ------------------------------------------------------------------------
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
// You may obtain a copy of the License at
|
|
|
//
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
//
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
// See the License for the specific language governing permissions and
|
|
|
// limitations under the License.
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
package acache
|
|
|
|
|
|
import (
|
|
|
"reflect"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
const(
|
|
|
|
|
|
kindBits = 16
|
|
|
)
|
|
|
|
|
|
|
|
|
var (
|
|
|
G = struct {
|
|
|
|
|
|
ErrInvalidKind ErrCode
|
|
|
ErrInvalidName ErrCode
|
|
|
ErrInvalidDeferFunc ErrCode
|
|
|
ErrDeferNotAllowed ErrCode
|
|
|
ErrFieldsReadOnly ErrCode
|
|
|
ErrDuplicatedField ErrCode
|
|
|
ErrDistinctType ErrCode
|
|
|
}{
|
|
|
ErrInvalidKind : ErrCode("invalid-valuerKind"),
|
|
|
ErrInvalidName : ErrCode("invalid-field-name"),
|
|
|
ErrInvalidDeferFunc : ErrCode("invalid-defer-func"),
|
|
|
ErrDeferNotAllowed : ErrCode("defer-field-not-allow"),
|
|
|
ErrFieldsReadOnly : ErrCode("fields-read-only"),
|
|
|
ErrDuplicatedField : ErrCode("duplicate-field-name"),
|
|
|
ErrDistinctType : ErrCode("distinct-field-types"),
|
|
|
|
|
|
}
|
|
|
|
|
|
g = struct {
|
|
|
timeZero time.Time
|
|
|
reflectZero reflect.Value
|
|
|
|
|
|
kindNames []string
|
|
|
|
|
|
/* 🚫 DEPRECATED
|
|
|
constructors map[reflect.Type]func(name string, valueFn any) Field
|
|
|
*/
|
|
|
|
|
|
}{
|
|
|
kindNames : []string{
|
|
|
"any",
|
|
|
"bool",
|
|
|
"binary",
|
|
|
"string",
|
|
|
"int",
|
|
|
"uint",
|
|
|
"float",
|
|
|
"time",
|
|
|
"duration",
|
|
|
"error",
|
|
|
"reflect",
|
|
|
"",
|
|
|
"",
|
|
|
"",
|
|
|
"defer",
|
|
|
},
|
|
|
|
|
|
/* 🚫 DEPRECATED : Tiene mejor rendimiento con el type switch, se descarta
|
|
|
|
|
|
constructors: map[reflect.Type] func(name string, valueFn any) Field {
|
|
|
reflect.TypeOf(false) : func(n string, v any) Field { return NewFieldBool (n,v.(bool)) },
|
|
|
reflect.TypeOf([]byte{}) : func(n string, v any) Field { return NewFieldBinary(n,v.([]byte))} ,
|
|
|
reflect.TypeOf("") : func(n string, v any) Field { return NewFieldString(n,v.(string))},
|
|
|
|
|
|
reflect.TypeOf(int(0)) : func(n string, v any) Field { return NewFieldInt (n,v.(int))},
|
|
|
reflect.TypeOf(int8 (0)) : func(n string, v any) Field { return NewFieldInt (n,int(v.(int8)))},
|
|
|
reflect.TypeOf(int16(0)) : func(n string, v any) Field { return NewFieldInt (n,int(v.(int32)))},
|
|
|
reflect.TypeOf(int32(0)) : func(n string, v any) Field { return NewFieldInt (n,int(v.(int32)))},
|
|
|
reflect.TypeOf(int64(0)) : func(n string, v any) Field { return NewFieldInt (n,int(v.(int64)))},
|
|
|
|
|
|
reflect.TypeOf(uint (0)) : func(n string, v any) Field { return NewFieldUint (n,v.(uint))},
|
|
|
reflect.TypeOf(uint8 (0)) : func(n string, v any) Field { return NewFieldUint (n,uint(v.(uint8)))},
|
|
|
reflect.TypeOf(uint16(0)) : func(n string, v any) Field { return NewFieldUint (n,uint(v.(uint32)))},
|
|
|
reflect.TypeOf(uint32(0)) : func(n string, v any) Field { return NewFieldUint (n,uint(v.(uint32)))},
|
|
|
reflect.TypeOf(uint64(0)) : func(n string, v any) Field { return NewFieldUint (n,uint(v.(uint64)))},
|
|
|
|
|
|
reflect.TypeOf(float64(0)): func(n string, v any) Field { return NewFieldFloat(n,v.(float64))},
|
|
|
reflect.TypeOf(float32(0)): func(n string, v any) Field { return NewFieldFloat(n,float64(v.(float32)))},
|
|
|
|
|
|
reflect.TypeOf(time.Time{}) : func(n string, v any) Field { return NewFieldTime(n,v.(time.Time))},
|
|
|
reflect.TypeOf(time.Duration(0)): func(n string, v any) Field { return NewFieldDuration(n,v.(time.Duration))},
|
|
|
|
|
|
reflect.TypeOf(reflect.Value{}) : func(n string, v any) Field { return NewFieldReflect(n,v.(reflect.Value))},
|
|
|
|
|
|
reflect.TypeOf(func() any (nil)): func(n string, v any) Field { return NewDFieldAny (n,v.(func()any)) },
|
|
|
reflect.TypeOf(func() bool (nil)): func(n string, v any) Field { return NewDFieldBool (n,v.(func()bool))},
|
|
|
reflect.TypeOf(func() []byte(nil)): func(n string, v any) Field { return NewDFieldBinary(n,v.(func()[]byte))},
|
|
|
reflect.TypeOf(func() string(nil)): func(n string, v any) Field { return NewDFieldString(n,v.(func()string))},
|
|
|
|
|
|
reflect.TypeOf(func() int (nil)): func(n string, v any) Field { return NewDFieldInt(n,v.(func()int)) } ,
|
|
|
reflect.TypeOf(func() int8 (nil)): func(n string, v any) Field { return NewDFieldInt(n,func() int { return int(v.(func()int8)()) }) },
|
|
|
reflect.TypeOf(func() int16 (nil)): func(n string, v any) Field { return NewDFieldInt(n,func() int { return int(v.(func()int16)()) }) },
|
|
|
reflect.TypeOf(func() int32 (nil)): func(n string, v any) Field { return NewDFieldInt(n,func() int { return int(v.(func()int32)()) }) },
|
|
|
reflect.TypeOf(func() int64 (nil)): func(n string, v any) Field { return NewDFieldInt(n,func() int { return int(v.(func()int64)()) }) },
|
|
|
|
|
|
reflect.TypeOf(func() uint (nil)): func(n string, v any) Field { return NewDFieldUint(n,v.(func()uint)) },
|
|
|
reflect.TypeOf(func() uint8 (nil)): func(n string, v any) Field { return NewDFieldUint(n,func() uint { return uint(v.(func()uint8)()) }) },
|
|
|
reflect.TypeOf(func() uint16 (nil)): func(n string, v any) Field { return NewDFieldUint(n,func() uint { return uint(v.(func()uint16)()) }) },
|
|
|
reflect.TypeOf(func() uint32 (nil)): func(n string, v any) Field { return NewDFieldUint(n,func() uint { return uint(v.(func()uint32)()) }) },
|
|
|
reflect.TypeOf(func() uint64 (nil)): func(n string, v any) Field { return NewDFieldUint(n,func() uint { return uint(v.(func()uint64)()) }) },
|
|
|
reflect.TypeOf(func() uintptr(nil)): func(n string, v any) Field { return NewDFieldUint(n,func() uint { return uint(v.(func()uintptr)()) }) },
|
|
|
|
|
|
reflect.TypeOf(func() float64(nil)): func(n string, v any) Field { return NewDFieldFloat(n,v.(func()float64)) },
|
|
|
reflect.TypeOf(func() float32(nil)): func(n string, v any) Field { return NewDFieldFloat(n,func()float64{ return float64(v.(func()float32)()) }) },
|
|
|
reflect.TypeOf(func() error (nil)): func(n string, v any) Field { return NewDFieldError(n,v.(func()error)) },
|
|
|
|
|
|
reflect.TypeOf(func() time.Time (nil)): func(n string, v any) Field { return NewDFieldTime(n,v.(func()time.Time)) },
|
|
|
reflect.TypeOf(func() time.Duration(nil)): func(n string, v any) Field { return NewDFieldDuration(n,v.(func()time.Duration)) },
|
|
|
|
|
|
reflect.TypeOf(func() reflect.Value(nil)): func(n string, v any) Field { return NewDFieldReflect(n,v.(func()reflect.Value))},
|
|
|
|
|
|
},
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
}
|
|
|
)
|
|
|
|
|
|
|
|
|
|