Paquete aflds creado

master
DEV 2 years ago
parent 5efcc0cdde
commit 0459127861

@ -2,7 +2,9 @@
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/Z" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>

@ -19,18 +19,21 @@
// 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.
// ------------------------------------------------------------------------
// ------------------------------------------------------------A------------
package AATest
import (
"acache"
"aflds"
"fields"
"testing"
)
func BenchmarkA (b *testing.B) {
func BenchmarkAflds (b *testing.B) {
for i := 0; i < b.N; i++ {
aflds.NewFieldString("f1", "value")
aflds.NewFieldUint("f2", 11)
aflds.NewFieldInt("f3", -11)
@ -39,12 +42,123 @@ func BenchmarkA (b *testing.B) {
aflds.NewDFieldInt("d1",func()int{ return -3 })
aflds.NewDFieldUint("d2",func()uint{ return uint(3) })
aflds.NewDFieldFloat("f2",func()float64{ return 3.2})
}
}
func BenchmarkAcache (b *testing.B) {
for i := 0; i < b.N; i++ {
acache.NewFieldString("f1", "value")
acache.NewFieldUint("f2", 11)
acache.NewFieldInt("f3", -11)
acache.NewFieldFloat("f4", 2.3)
acache.NewFieldBinary("f5", []byte{1,2,2,4,3,3,3,3})
acache.NewDFieldInt("d1",func()int{ return -3 })
acache.NewDFieldUint("d2",func()uint{ return uint(3) })
acache.NewDFieldFloat("f2",func()float64{ return 3.2})
}
}
func BenchmarkAFields (b *testing.B) {
for i := 0; i < b.N; i++ {
fields.NewFieldString("f1", "value")
fields.NewFieldUint("f2", 11)
fields.NewFieldInt("f3", -11)
fields.NewFieldFloat("f4", 2.3)
fields.NewFieldBinary("f5", []byte{1,2,2,4,3,3,3,3})
fields.NewDFieldInt("d1",func()int{ return -3 })
fields.NewDFieldUint("d2",func()uint{ return uint(3) })
fields.NewDFieldFloat("f2",func()float64{ return 3.2})
}
}
/*
func BenchmarkA1 (b *testing.B) {
for i := 0; i < b.N; i++ {
aflds.NewDFieldString("f1", func() string { return "value" })
aflds.NewDFieldUint("f2", func () uint { return uint(11) })
aflds.NewDFieldInt("f3", func () int { return -11 })
aflds.NewDFieldFloat("f4",func() float64 { return 2.3 })
aflds.NewDFieldBinary("f5",func() []byte { return []byte{1,2,2,4,3,3,3,3} })
aflds.NewDFieldInt("d1",func()int{ return -3 })
aflds.NewDFieldUint("d2",func()uint{ return uint(3) })
aflds.NewDFieldFloat("f2",func()float64{ return 3.2})
}
}
*/
func BenchmarkAfldsAcc (b *testing.B) {
var d[8]any
flds := []aflds.Field {
aflds.NewFieldString("f1", "value"),
aflds.NewFieldUint("f2", 11),
aflds.NewFieldInt("f3", -11),
aflds.NewFieldFloat("f4", 2.3),
aflds.NewFieldBinary("f5", []byte{1,2,2,4,3,3,3,3}),
aflds.NewDFieldInt("d1",func()int{ return -3 }),
aflds.NewDFieldUint("d2",func()uint{ return uint(3) }),
aflds.NewDFieldFloat("f2",func()float64{ return 3.2}),
}
for i := 0; i < b.N; i++ {
for i:=0; i<8; i++ {
d[i]=flds[i].Value()
}
}
}
func BenchmarkAcacheAcc (b *testing.B) {
var d[8]any
flds := []acache.Field {
acache.NewDFieldString("f1", func() string { return "value" }),
acache.NewDFieldUint("f2", func () uint { return uint(11) }),
acache.NewDFieldInt("f3", func () int { return -11 }),
acache.NewDFieldFloat("f4",func() float64 { return 2.3 }),
acache.NewDFieldBinary("f5",func() []byte { return []byte{1,2,2,4,3,3,3,3} }),
acache.NewDFieldInt("d1",func()int{ return -3 }),
acache.NewDFieldUint("d2",func()uint{ return uint(3) }),
acache.NewDFieldFloat("f2",func()float64{ return 3.2}),
}
for i := 0; i < b.N; i++ {
for i:=0; i<8; i++ {
d[i]=flds[i].Value()
}
}
}
func BenchmarkAFieldsAcc (b *testing.B) {
var d[8]any
flds := []fields.Field {
fields.NewDFieldString("f1", func() string { return "value" }),
fields.NewDFieldUint("f2", func () uint { return uint(11) }),
fields.NewDFieldInt("f3", func () int { return -11 }),
fields.NewDFieldFloat("f4",func() float64 { return 2.3 }),
fields.NewDFieldBinary("f5",func() []byte { return []byte{1,2,2,4,3,3,3,3} }),
fields.NewDFieldInt("d1",func()int{ return -3 }),
fields.NewDFieldUint("d2",func()uint{ return uint(3) }),
fields.NewDFieldFloat("f2",func()float64{ return 3.2}),
}
for i := 0; i < b.N; i++ {
for i:=0; i<8; i++ {
d[i]=flds[i].Value()
}
}
}
/*
func BenchmarkB (b *testing.B) {
func BenchmarkA2 (b *testing.B) {
for i := 0; i < b.N; i++ {
aflds.Create("f1", "value",aflds.KindString)
aflds.Create("f2", uint(11),aflds.KindUint)
@ -57,7 +171,7 @@ func BenchmarkB (b *testing.B) {
}
}
func BenchmarkC (b *testing.B) {
func BenchmarkA3 (b *testing.B) {
for i := 0; i < b.N; i++ {
aflds.CreateFromValue("f1", "value")
aflds.CreateFromValue("f2", 11)
@ -70,3 +184,4 @@ func BenchmarkC (b *testing.B) {
}
}
*/

@ -0,0 +1,3 @@
module AATest
go 1.22

@ -0,0 +1,3 @@
module ablds
go 1.22

@ -28,8 +28,8 @@ package ablds
type (
ListBuilder interface {
Ender
Item () ValueBuilder
Item () Builder
}

@ -27,8 +27,6 @@ package ablds
type (
MapBuilder interface {
Ender
Element (key any) Builder
}
)

@ -28,9 +28,7 @@ package ablds
type (
ObjectBuilder interface {
Ender
Field (name string) Builder
}
)

@ -0,0 +1,152 @@
// ------------------------------------------------------------------------
// ℹ️ 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))},
},
*/
}
)

@ -0,0 +1,46 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name err_code.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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
type (
ErrCode string
)
func (e ErrCode) Error () string {
return string(e) }
func (e ErrCode) Code () string {
return string(e) }
func (_ ErrCode) Unwrap() error {
return nil }
func (_ ErrCode) UnwrapAll() []error {
return nil }

@ -0,0 +1,246 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name factory.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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"
)
// Create es un método que crea y devuelve un nuevo campo con el nombre, valor y tipo especificados.
// Este método es utilizado para crear campos de diferentes tipos según el valor del tipo Kind proporcionado.
// Si el tipo Kind es KindAny, el campo se crea utilizando el valor y su tipo se infiere automáticamente.
//
// Parámetros:
// - name: El nombre del campo que se va a crear.
// - valueFn: El valor del campo que se va a asignar.
// - valuerKind: El tipo de campo que se va a crear, representado por un valor de la enumeración Kind.
// Devuelve:
// - Field: El campo creado con el nombre, valor y tipo especificados.
// Pánico:
// - Si se proporciona un tipo de Kind inválido, el método entra en un estado de pánico y devuelve un error ErrInvalidKind.
func Create (name string, value any, kind Kind) Field {
if kind == 0 {
return CreateFromValue(name,value)
}
switch kind {
case KindAny : return NewFieldAny (name,value)
case KindBool : return NewFieldBool (name,value.(bool))
case KindBinary : return NewFieldBinary(name,value.([]byte))
case KindString : return NewFieldString(name,value.(string))
case KindInt : return NewFieldInt (name,value.(int))
case KindUint : return NewFieldUint (name,value.(uint))
case KindFloat : return NewFieldFloat (name,value.(float64))
case KindTime : return NewFieldTime (name,value.(time.Time))
case KindDuration:return NewFieldDuration(name,value.(time.Duration))
case KindError : return NewFieldError (name,value.(error))
case KindReflect : return NewFieldReflect(name,value.(reflect.Value))
//valuerKind Fields
case KindDefer,
KindDeferAny : return NewDFieldAny (name,value.(func()any))
case KindDeferBool : return NewDFieldBool (name,value.(func()bool))
case KindDeferString : return NewDFieldString(name,value.(func()string))
case KindDeferBinary : return NewDFieldBinary(name,value.(func()[]byte))
case KindDeferInt : return NewDFieldInt (name,value.(func()int))
case KindDeferUint : return NewDFieldUint (name,value.(func()uint))
case KindDeferFloat : return NewDFieldFloat (name,value.(func()float64))
case KindDeferTime : return NewDFieldTime (name,value.(func()time.Time))
case KindDeferDuration:return NewDFieldDuration (name,value.(func()time.Duration))
case KindDeferError : return NewDFieldError (name,value.(func()error))
case KindDeferReflect :return NewDFieldReflect(name,value.(func()reflect.Value))
default:
panic(G.ErrInvalidKind)
}
}
// CreateFromValue es un método que crea y devuelve un nuevo campo basado en el valor proporcionado.
// Examina el tipo del valor y crea un campo correspondiente, asignando el nombre especificado.
// Si el tipo del valor no coincide con ninguno de los tipos predefinidos, se crea un campo genérico utilizando el tipo KindAny.
//
// Parámetros:
// - name: El nombre del campo que se va a crear.
// - valueFn: El valor del campo que se va a asignar.
// Devuelve:
// - Field: El campo creado con el nombre y valor especificados.
func CreateFromValue(name string, value any) Field {
switch t := value.(type) {
case bool : return NewFieldBool (name,t)
case []byte : return NewFieldBinary (name,t)
case string : return NewFieldString (name,t)
case int : return NewFieldInt (name,t)
case int8 : return NewFieldInt (name,int(t))
case int16 : return NewFieldInt (name,int(t))
case int32 : return NewFieldInt (name,int(t))
case int64 : return NewFieldInt (name,int(t))
case uint : return NewFieldUint (name,t)
case uint8 : return NewFieldUint (name,uint(t))
case uint16 : return NewFieldUint (name,uint(t))
case uint32 : return NewFieldUint (name,uint(t))
case uint64 : return NewFieldUint (name,uint(t))
case uintptr: return NewFieldUint (name,uint(t))
case float64: return NewFieldFloat(name,t)
case float32: return NewFieldFloat(name,float64(t))
case error : return NewFieldError(name,t)
case time.Time:
return NewFieldTime (name,t)
case time.Duration:
return NewFieldDuration (name,t)
case reflect.Value :
return NewFieldReflect(name,t)
case func() any : return NewDFieldAny (name,t)
case func() bool : return NewDFieldBool(name,t)
case func() []byte : return NewDFieldBinary(name,t)
case func() string : return NewDFieldString(name,t)
case func() int : return NewDFieldInt (name,t)
case func() int8 : return NewDFieldInt (name,func() int { return int(t()) })
case func() int16 : return NewDFieldInt (name,func() int { return int(t()) })
case func() int32 : return NewDFieldInt (name,func() int { return int(t()) })
case func() int64 : return NewDFieldInt (name,func() int { return int(t()) })
case func() uint : return NewDFieldUint(name,t)
case func() uint8 : return NewDFieldUint(name,func() uint { return uint(t()) })
case func() uint16 : return NewDFieldUint(name,func() uint { return uint(t()) })
case func() uint32 : return NewDFieldUint(name,func() uint { return uint(t()) })
case func() uint64 : return NewDFieldUint(name,func() uint { return uint(t()) })
case func() uintptr: return NewDFieldUint(name,func() uint { return uint(t()) })
case func() float64: return NewDFieldFloat(name,t)
case func() float32: return NewDFieldFloat(name,func() float64 { return float64(t()) })
case func() error : return NewDFieldError(name,t)
case func() time.Time :
return NewDFieldTime(name,t)
case func() time.Duration :
return NewDFieldDuration(name,t)
case func() reflect.Value :
return NewDFieldReflect(name,t)
default:
if value != nil {
rv := reflect.ValueOf(value)
if rv.Kind() == reflect.Func {
tp := rv.Type()
if tp.NumIn() == 0 && tp.NumOut() == 1 {
return NewDFieldAny(name, func() any {
return rv.Call(nil)[0].Interface()
})
}
}
}
return NewFieldAny(name,value)
}
}
// TypeToKind es una función que determina el tipo de Kind correspondiente al valor proporcionado.
// Examina el tipo del valor y devuelve un tipo Kind adecuado que representa el tipo del valor.
// Si el valor es una función, el tipo Kind resultante tendrá la bandera KindDefer para indicar que es una función deferida.
//
// Parámetros:
// - valueFn: El valor del cual se determinará el tipo Kind.
// Devuelve:
// - Kind: El tipo Kind correspondiente al valor proporcionado.
func TypeToKind(value any) Kind {
switch value.(type) {
case bool:
return KindAny
case []byte :
return KindBinary
case string :
return KindString
case int,
int8,
int16,
int32,
int64 :
return KindInt
case uint,
uint8,
uint16,
uint32,
uint64,
uintptr : return KindUint
case float64,
float32:
return KindFloat
case error :
return KindError
case time.Time:
return KindTime
case reflect.Value:
return KindReflect
case func() any :
return KindAny|KindDefer
case func() bool :
return KindBool|KindDefer
case func() []byte :
return KindBinary|KindDefer
case func() string :
return KindString|KindDefer
case func() int,
func() int8,
func() int16,
func() int32,
func() int64 :
return KindInt|KindDefer
case func() uint,
func() uint8,
func() uint16,
func() uint32,
func() uint64,
func() uintptr :
return KindInt|KindDefer
case func() float64,
func() float32 :
return KindFloat|KindDefer
case func() error :
return KindError|KindDefer
case func() time.Time:
return KindTime|KindDefer
case func() reflect.Value:
return KindReflect|KindDefer
default:
rt := reflect.TypeOf(value)
if rt.Kind() == reflect.Func && rt.NumIn() == 0 && rt.NumOut() == 1 {
return KindAny|KindDefer
}
return KindAny
}
}

@ -0,0 +1,70 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 "ablds"
type (
Field interface {
NativeResolver
Kind () Kind
Name () string
Value() any
}
)
func FieldAsBuildable (field Field) ablds.BuildFnc {
return func (b ablds.Builder) {
buildFieldAsObject(field,b)
}
}
func buildFieldAsObject (field Field, builder ablds.Builder) {
builder.Object(func(ob ablds.ObjectBuilder){
buildFieldAsField(field,ob)
})
}
func buildFieldAsField (field Field, obuilder ablds.ObjectBuilder) {
vb := obuilder.Field(field.Name())
switch field.Kind() {
case KindAny : vb.Any (field.Value())
case KindBool : v,_ := field.Bool(); vb.Bool(v)
case KindBinary : v,_ := field.Binary(); vb.Binary(v)
case KindString : v,_ := field.String(); vb.String(v)
case KindInt : v,_ := field.Int(); vb.Int(v)
case KindUint : v,_ := field.Uint(); vb.Uint(v)
case KindFloat : v,_ := field.Float(); vb.Float64(v)
case KindTime : v,_ := field.Time(); vb.Time(v)
case KindDuration: v,_ := field.Duration(); vb.Duration(v)
case KindError : v,_ := field.Error(); vb.Error(v)
case KindReflect : v,_ := field.Reflect(); vb.Reflect(v)
default:
vb.Any(field.Value())
}
}

@ -0,0 +1,148 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_any.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 (
"ablds"
"reflect"
"time"
)
type (
FieldAny struct {
partialField
valuerMode
valueFn func() any
}
)
func NewFieldAny (name string, value any) *FieldAny {
return &FieldAny{
partialField : makePartialField(name),
valuerMode: localValuer{},
valueFn : func() any { return value },
}
}
func NewDFieldAny (name string, valueFn func() any) *FieldAny {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldAny{
partialField: makePartialField(name),
valuerMode: deferValuer{},
valueFn : valueFn,
}
}
func (f FieldAny) Kind() Kind {
return KindAny | f.valuerKind() }
func (f FieldAny) Value() any {
return f.valueFn() }
func (f FieldAny) Bool () (bool,bool) {
v,ok := f.valueFn().(bool)
return v,ok
}
func (f FieldAny) Binary () ([]byte,bool) {
v, ok := f.valueFn().([]byte)
return v, ok
}
func (f FieldAny) String () (string,bool) {
v,ok := f.valueFn().(string)
return v,ok
}
func (f FieldAny) Int () (int,bool) {
switch t := f.valueFn().(type) {
case int : return t,true
case int8 : return int(t),true
case int16: return int(t),true
case int32: return int(t),true
case int64: return int(t),true
default : return 0,false
}
}
func (f FieldAny) Uint () (uint,bool) {
switch t := f.valueFn().(type) {
case uint : return t,true
case uint8 : return uint(t),true
case uint16: return uint(t),true
case uint32: return uint(t),true
case uint64: return uint(t),true
default : return 0,false
}
}
func (f FieldAny) Float () (float64,bool) {
v, ok := f.valueFn().(float64)
if !ok {
var f32 float32
if f32,ok = f.valueFn().(float32); ok {
v = float64(f32)
}
}
return v, ok
}
func (f FieldAny) Date () (time.Time,bool) {
v, ok := f.valueFn().(time.Time)
return v, ok
}
func (f FieldAny) Time () (time.Time,bool) {
v, ok := f.valueFn().(time.Time)
return v, ok
}
func (f FieldAny) Error () (error,bool) {
v, ok := f.valueFn().(error)
return v, ok
}
func (f FieldAny) Reflect () (reflect.Value,bool) {
v, ok := f.valueFn().(reflect.Value)
return v, ok
}
func (f FieldAny) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Any(f.valueFn()) }) }

@ -0,0 +1,73 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_binary.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 "ablds"
type (
FieldBinary struct {
partialField
valuerMode
valueFn func()[]byte
}
)
func NewFieldBinary (name string, value []byte) *FieldBinary {
return &FieldBinary{
partialField: makePartialField(name),
valuerMode: localValuer{},
valueFn: func()[]byte { return value },
}
}
func NewDFieldBinary (name string, valueFn func() []byte) *FieldBinary {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldBinary {
partialField: makePartialField(name),
valuerMode: deferValuer{},
valueFn : valueFn,
}
}
func (f FieldBinary) Kind () Kind {
return KindBinary | f.valuerKind() }
func (f FieldBinary) Value() any {
return f.valueFn
}
func (f FieldBinary) Binary() ([]byte,bool) {
return f.valueFn(),true }
func (f FieldBinary) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Binary(f.valueFn()) }) }

@ -0,0 +1,73 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_bool.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 "ablds"
type (
FieldBool struct {
partialField
valuerMode
valueFn func() bool
}
)
func NewFieldBool (name string, value bool) *FieldBool {
return &FieldBool{
partialField: makePartialField(name),
valuerMode: localValuer{},
valueFn : func() bool { return value },
}
}
func NewDFieldBool (name string, valueFn func() bool) *FieldBool {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldBool{
partialField: makePartialField(name),
valuerMode: deferValuer{},
valueFn : valueFn,
}
}
func (f FieldBool) Kind () Kind {
return KindBool | f.valuerKind() }
func (f FieldBool) Value() any {
return f.valueFn
}
func (f FieldBool) Bool() (bool,bool) {
return f.valueFn(),true }
func (f FieldBool) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Bool(f.valueFn()) }) }

@ -0,0 +1,76 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_time.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 (
"ablds"
"time"
)
type (
FieldDuration struct {
partialField
valuerMode
valueFn func () time.Duration
}
)
func NewFieldDuration (name string, value time.Duration) *FieldDuration {
return &FieldDuration{
partialField: makePartialField(name),
valuerMode: localValuer{},
valueFn: func() time.Duration { return value },
}
}
func NewDFieldDuration (name string, valueFn func() time.Duration) *FieldDuration {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldDuration{
partialField: makePartialField(name),
valuerMode: deferValuer{},
valueFn : valueFn,
}
}
func (f FieldDuration) Kind () Kind {
return KindDuration | f.valuerKind() }
func (f FieldDuration) Value() any {
return f.valueFn
}
func (f FieldDuration) Duration() (time.Duration,bool) {
return f.valueFn(),true }
func (f FieldDuration) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Duration(f.valueFn()) }) }

@ -0,0 +1,73 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_error.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 "ablds"
type (
FieldError struct {
partialField
valuerMode
valueFn func() error
}
)
func NewFieldError (name string, value error) *FieldError {
return &FieldError{
partialField: makePartialField(name),
valuerMode: localValuer{},
valueFn: func() error { return value },
}
}
func NewDFieldError (name string, valueFn func() error) *FieldError {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldError{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn,
}
}
func (f FieldError) Kind () Kind {
return KindError | f.valuerKind() }
func (f FieldError) Value() any {
return f.valueFn
}
func (f FieldError) Error() (error,bool) {
return f.valueFn(),true }
func (f FieldError) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Error(f.valueFn()) }) }

@ -0,0 +1,70 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_float.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 "ablds"
type (
FieldFloat struct {
partialField
valuerMode
valueFn func() float64
}
)
func NewFieldFloat (name string, value float64) *FieldFloat {
return &FieldFloat{
partialField: makePartialField(name),
valuerMode : localValuer{},
valueFn : func() float64 { return value },
}
}
func NewDFieldFloat (name string, valueFn func()float64) *FieldFloat {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldFloat{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn } }
func (f FieldFloat) Kind () Kind {
return KindFloat | f.valuerKind() }
func (f FieldFloat) Value() any {
return f.valueFn()
}
func (f FieldFloat) Float() (float64,bool) {
return f.valueFn(),true }
func (f FieldFloat) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Float64(f.valueFn())
})
}

@ -0,0 +1,74 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_int.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 "ablds"
type (
FieldInt struct {
partialField
valuerMode
valueFn func()int
}
)
func NewFieldInt (name string, value int) *FieldInt {
return &FieldInt{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : func() int { return value },
}
}
func NewDFieldInt (name string, valueFn func()int) *FieldInt {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldInt{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn,
}
}
func (f FieldInt) Kind () Kind {
return KindInt | f.valuerKind() }
func (f FieldInt) Value() any {
return f.valueFn() }
func (f FieldInt) Int() (int,bool) {
return f.valueFn(),true }
func (f FieldInt) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Int(f.valueFn()) }) }

@ -0,0 +1,76 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_reflect.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 (
"ablds"
"reflect"
)
type (
FieldReflect struct {
partialField
valuerMode
valueFn func() reflect.Value
}
)
func NewFieldReflect (name string, value reflect.Value) *FieldReflect {
return &FieldReflect{
partialField: makePartialField(name),
valuerMode : localValuer{},
valueFn : func() reflect.Value { return value },
}
}
func NewDFieldReflect (name string, valueFn func()reflect.Value) *FieldReflect {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldReflect{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn ,
}
}
func (f FieldReflect) Kind () Kind {
return KindReflect | f.valuerKind() }
func (f FieldReflect) Value() any {
return f.valueFn() }
func (f FieldReflect) Reflect() (reflect.Value,bool) {
return f.valueFn(),true }
func (f FieldReflect) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Reflect(f.valueFn()) }) }

@ -0,0 +1,74 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_string.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 "ablds"
type (
FieldString struct {
partialField
valuerMode
valueFn func() string
}
)
func NewFieldString (name string, value string) *FieldString {
return &FieldString{
partialField: makePartialField(name),
valuerMode: localValuer{},
valueFn: func() string { return value },
}
}
func NewDFieldString (name string, valueFn func()string) *FieldString {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldString{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn ,
}
}
func (f FieldString) Kind () Kind {
return KindString | f.valuerKind() }
func (f FieldString) Value() any {
return f.valueFn() }
func (f FieldString) String() (string,bool) {
return f.valueFn(),true }
func (f FieldString) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).String(f.valueFn())
})
}

@ -0,0 +1,76 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_time.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 (
"ablds"
"time"
)
type (
FieldTime struct {
partialField
valuerMode
valueFn func() time.Time
}
)
func NewFieldTime (name string, value time.Time) *FieldTime {
return &FieldTime{
partialField: makePartialField(name),
valuerMode: localValuer{},
valueFn: func() time.Time { return value },
}
}
func NewDFieldTime(name string, valueFn func()time.Time) *FieldTime {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldTime{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn ,
}
}
func (f FieldTime) Kind () Kind {
return KindTime | f.valuerKind() }
func (f FieldTime) Value() any {
return f.valueFn() }
func (f FieldTime) Time() (time.Time,bool) {
return f.valueFn(),true }
func (f FieldTime) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Time(f.valueFn()) }) }

@ -0,0 +1,73 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_unuint.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 "ablds"
type (
FieldUint struct {
partialField
valuerMode
valueFn func() uint
}
)
func NewFieldUint (name string, value uint) *FieldUint {
return &FieldUint{
partialField: makePartialField(name),
valuerMode: localValuer{},
valueFn: func() uint { return value },
}
}
func NewDFieldUint (name string, valueFn func()uint) *FieldUint {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldUint{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn ,
}
}
func (f FieldUint) Kind () Kind {
return KindInt | f.valuerKind() }
func (f FieldUint) Value() any {
return f.valueFn() }
func (f FieldUint) Uint() (uint,bool) {
return f.valueFn(),true }
func (f FieldUint) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Uint(f.valueFn()) }) }

@ -0,0 +1,143 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name fields.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 (
"ablds"
"sort"
)
type (
// Fields es un tipo que representa una lista de campos y proporciona métodos
// para gestionar y manipular dicha lista.
Fields []Field
)
func (f Fields) Len () int {
return len(f) }
func (f Fields) Has (name string) bool {
return f.indexOf(name) != -1 }
func (f Fields) Kinds() Kind {
var k Kind
for _,f := range f {
k|=f.Kind()
}
return k
}
func (f Fields) Get(name string) Field {
if p := f.indexOf(name); p != -1 {
return f[p]
}
return nil
}
func (f Fields) GetAll (name string) []Field {
var ls []Field
for _,fl := range f {
if fl.Name() == name {
ls = append(ls,fl)
}
}
return ls
}
func (f Fields) Add(field Field) Fields {
if field != nil {
return append(f,field)
}
return f
}
func (f Fields) Set(field Field) Fields {
if field == nil {
return f
}
if p := f.indexOf(field.Name()); p != -1 {
return append(append(f[:p],field), f[p+1:]...)
}
return append(f,field)
}
func (f Fields) Del(name string) Fields {
if p := f.indexOf(name); p != -1 {
return append(f[:p],f[p+1:]...)
}
return f
}
func (f Fields) DelAll (name string) Fields {
l := make(Fields,0,len(f))
c := 0
for i := 0; i<len(f); i++ {
if f[i].Name() == name {
l = append(l,f[c:i]...)
c = i+1
}
}
l = append(l,f[c:]...)
return l
}
func (f Fields) Sort() {
sort.Sort(f) }
func (f Fields) Swap(i, j int) {
f[i], f[j] = f[j], f[i] }
func (f Fields) Less(i, j int) bool {
return f[i].Name() < f[j].Name() }
func (f Fields) indexOf(name string) int {
for i,f := range f {
if f.Name() == name {
return i
}
}
return -1
}
func (f Fields) Build (builder ablds.Builder) {
builder.List(func(lb ablds.ListBuilder) {
for _,fl := range f {
buildFieldAsObject(fl,lb.Item())
}
})
}

@ -0,0 +1,57 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name atts.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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
const(
AttFieldsReadOnly FieldsAtt = 1 << iota
AttFieldsNotDefer
AttFieldsNotDuplicated
AttFieldSetSameKind
)
type (
// FieldsAtt representa los atributos asociados a los campos en un objeto FieldsObject
// y definen la forma en que este debe de gestionarlos y que se permite.
FieldsAtt uint8
)
func (a FieldsAtt) IsReadOnly () bool {
return a&AttFieldsReadOnly != 0 }
func (a FieldsAtt) IsNotDefer() bool {
return a&AttFieldsNotDefer != 0 }
func (a FieldsAtt) IsNotDuplicate() bool {
return a&AttFieldsNotDuplicated != 0 }
func (a FieldsAtt) IsSetSameKind () bool {
return a&AttFieldSetSameKind != 0 }

@ -0,0 +1,214 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name fieldsObject.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 (
"ablds"
"sort"
)
type (
// FieldsObject representa un objeto que contiene Fields. Este objeto proporciona métodos para gestionar y
// manipular estos campos de diversas formas, como agregar, eliminar, obtener y listar.
FieldsObject struct {
atts FieldsAtt
fields Fields
}
FieldsObjectFnc func(object *FieldsObject) error
)
func NewFieldsObject (options ...FieldsObjectFnc) (*FieldsObject,error) {
f := &FieldsObject{}
for _,o := range options {
if er := o(f); er != nil {
return nil,er
}
}
return f,nil
}
func (f *FieldsObject) Len () int {
return len(f.fields) }
func (f *FieldsObject) Has (name string) bool {
return f.fields.Has(name) }
func (f *FieldsObject) Kinds() Kind {
return f.fields.Kinds() }
func (f *FieldsObject) Get(name string) Field {
return f.fields.Get(name) }
func (f *FieldsObject) GetAll (name string) []Field {
if f.atts.IsNotDuplicate() {
f := f.fields.Get(name)
if f != nil {
return []Field{f}
}
return nil
}
return f.fields.GetAll(name)
}
func (f *FieldsObject) New(name string, value any, kind Kind) error {
return f.Add(Create(name,value,kind)) }
// Add agrega un nuevo campo al objeto FieldsObject.
// Si el objeto está configurado como de solo lectura, // devuelve un error ErrFieldsReadOnly.
// Si se especifica que no se permiten campos duplicados y se intenta agregar un // campo que ya existe con el mismo
// nombre, devuelve un error ErrDuplicatedField.
// Si se especifica que los campos deben ser del mismo tipo y se intenta agregar un campo con un tipo diferente al de
// los campos existentes con el mismo nombre, devuelve un error ErrDistinctType.
//
// Parámetros:
// - field: El campo que se va a agregar al objeto FieldsObject.
// Devuelve:
// - error: Un error, si ocurre alguno; de lo contrario, nil.
//
// Por motivos de prestaciones es recomendable usar la creación específica de cada
// campo que no la creación a través de la factoría con la llamada a New.
func (f *FieldsObject) Add(field Field) error {
if f.atts.IsReadOnly() {
return G.ErrFieldsReadOnly
}
if p := f.fields.indexOf(field.Name()); p != -1 {
if f.atts.IsNotDuplicate() {
return G.ErrDuplicatedField
}
if f.atts.IsSetSameKind() && f.fields[p].Kind() != field.Kind() {
return G.ErrDistinctType
}
}
f.fields = f.fields.Add(field)
return nil
}
// Set sustituye o añade un Field al objeto de Fields
// Si los atributos del objeto es de solo lectura, devuelve un error ErrFieldsReadOnly.
// Si los atributos del objeto no permite defers y se intenta agregar un campo defer, devuelve un error ErrDeferNotAllowed.
// Si los atributos del objeto requiere que el Field por el que se sustituye en su caso sean del mismo tipo, si se intenta
// agregar un campo de un tipo diferente, devuelve un error ErrDistinctType.
//
// Parámetros:
// - field: El campo que se agregará al objeto de campos.
// Devuelve:
// - error: Un error, si ocurre alguno; de lo contrario, nil.
func (f *FieldsObject) Set(field Field) error {
if f.atts.IsReadOnly() {
return G.ErrFieldsReadOnly
}
if f.atts.IsNotDefer() && field.Kind().IsDefer() {
return G.ErrDeferNotAllowed
}
if p := f.fields.indexOf(field.Name()); p != -1 {
if f.atts.IsSetSameKind() && field.Kind() != f.fields[p].Kind() {
return G.ErrDistinctType
}
f.fields[p]=field
} else {
f.fields = f.fields.Add(field)
}
return nil
}
func (f *FieldsObject) Del(name string) error {
if f.atts.IsReadOnly() {
return G.ErrFieldsReadOnly
}
f.fields = f.fields.Del(name)
return nil
}
// DelAll elimina todos los campos con el nombre especificado del objeto de campos.
// Si el objeto de atributos asociado a los campos es de solo lectura, devuelve un error ErrFieldsReadOnly.
// Si el nombre proporcionado está vacío, elimina todos los campos del objeto de campos.
//
// Parámetros:
// - name: El nombre del campo que se eliminará.
// Devuelve:
// - error: Un error, si ocurre alguno; de lo contrario, nil.
func (f *FieldsObject) DelAll (name string) error {
if f.atts.IsReadOnly() {
return G.ErrFieldsReadOnly
}
if len(name) == 0 {
f.fields = f.fields[:0]
return nil
}
if f.atts.IsNotDuplicate() {
f.fields = f.fields.Del(name)
return nil
}
f.fields = f.fields.DelAll(name)
return nil
}
func (f *FieldsObject) List() Fields {
return f.fields }
func (f *FieldsObject) Sort() {
if f.atts.IsReadOnly() {
return
}
sort.Sort(f.fields) }
func (f *FieldsObject) Build (builder ablds.Builder) {
builder.Object(func(ob ablds.ObjectBuilder) {
for _,fl := range f.fields {
buildFieldAsField(fl,ob)
}
})
}
func FieldsObjectWithAtts (set FieldsAtt) FieldsObjectFnc {
return func(f *FieldsObject) error {
f.atts = set
return nil } }
func FieldsObjectWithField(field Field) FieldsObjectFnc {
return func(f *FieldsObject) error {
return f.Add(field) } }
func FieldsObjectWithNew (name string, value any, kind Kind) FieldsObjectFnc {
return func(f *FieldsObject) error {
return f.New(name,value,kind) } }

@ -0,0 +1,3 @@
module acache
go 1.22

@ -0,0 +1,144 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name att.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 "math/bits"
const(
KindAny Kind = 1 << iota
KindBool
KindBinary
KindString
KindInt
KindUint
KindFloat
KindTime
KindDuration
KindError
KindReflect
KindDefer Kind = 16384
)
const(
KindDeferAny = KindDefer|KindAny
KindDeferBool = KindDefer|KindBool
KindDeferString = KindDefer|KindString
KindDeferBinary = KindDefer|KindBinary
KindDeferInt = KindDefer|KindInt
KindDeferUint = KindDefer|KindUint
KindDeferFloat = KindDefer|KindFloat
KindDeferTime = KindDefer|KindTime
KindDeferDuration = KindDefer|KindDuration
KindDeferError = KindDefer|KindError
KindDeferReflect = KindDefer|KindReflect
)
type (
Kind uint16
)
func (k Kind) IsAny() bool {
return k&KindAny != 0 }
func (k Kind) IsBool() bool {
return k&KindBool != 0 }
func (k Kind) IsInt() bool {
return k&KindInt != 0 }
func (k Kind) IsUint() bool {
return k&KindUint != 0 }
func (k Kind) IsFloat() bool {
return k&KindFloat != 0 }
func (k Kind) IsString() bool {
return k&KindString != 0 }
func (k Kind) IsTime() bool {
return k&KindTime != 0 }
func (k Kind) IsDuration() bool {
return k&KindDuration != 0 }
func (k Kind) IsBinary() bool {
return k&KindBinary != 0 }
func (k Kind) IsError() bool {
return k&KindError != 0 }
func (k Kind) IsReflect() bool {
return k&KindReflect != 0 }
func (k Kind) IsDefer() bool {
return k&KindDefer != 0 }
func (k Kind) Count () int {
return bits.OnesCount16(uint16(k)) }
func (k Kind) Kinds () []Kind {
if k == 0 {
return nil
}
var ls []Kind
c := Kind(1)
for i:=0; i< kindBits; i++ {
c = 1 << i
if c&k != 0 {
ls = append(ls,c)
}
}
return ls
}
func (k Kind) KindNames () []string {
if k==0 {
return []string{""}
}
var ls []string
c := Kind(1)
for i:=0; i< kindBits; i++ {
c = 1 << i
if c&k != 0 {
ls = append(ls, g.kindNames[i])
}
}
return ls
}

@ -0,0 +1,78 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name value_resolver.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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"
)
type (
// NativeResolver es una interfaz que define métodos para resolver
// y obtener valores nativos de diferentes tipos, junto con un indicador
// de éxito para indicar si la resolución fue exitosa o no.
NativeResolver interface {
// Bool intenta resolver y devolver el valor como un booleano.
// Retorna el valor booleano y un indicador de éxito.
Bool() (bool, bool)
// Binary intenta resolver y devolver el valor como un slice de bytes.
// Retorna el slice de bytes y un indicador de éxito.
Binary() ([]byte, bool)
// String intenta resolver y devolver el valor como una cadena de texto.
// Retorna la cadena de texto y un indicador de éxito.
String() (string, bool)
// Int intenta resolver y devolver el valor como un entero.
// Retorna el entero y un indicador de éxito.
Int() (int, bool)
// Uint intenta resolver y devolver el valor como un entero sin signo.
// Retorna el entero sin signo y un indicador de éxito.
Uint() (uint, bool)
// Float intenta resolver y devolver el valor como un número flotante de punto flotante de 64 bits.
// Retorna el número flotante y un indicador de éxito.
Float() (float64, bool)
// Time intenta resolver y devolver el valor como una marca de tiempo.
// Retorna la marca de tiempo y un indicador de éxito.
Time() (time.Time, bool)
// Duration intenta resolver y devolver el valor como una duración de tiempo
// Retorna la duración y un indicador de éxito.
Duration() (time.Duration, bool)
// Error intenta resolver y devolver el valor como un error.
// Retorna el error y un indicador de éxito.
Error() (error, bool)
// Reflect intenta resolver y devolver el valor como un reflect.Value.
// Retorna el reflect.Value y un indicador de éxito.
Reflect() (reflect.Value, bool)
}
)

@ -0,0 +1,80 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name partial_field.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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"
)
type (
// partialField representa un Field parcialmente definido con solo el nombre.
// Implementa el interface NativeResolver de forma nula para proporcionar valores
// predeterminados para los tipos de datos comunes. Cuando un objeto Field
// sobrescribe alguno de estos métodos, se produce shadowing, lo que significa
// que la implementación en Field prevalecerá sobre la implementación nula de
// partialField.
partialField struct {
name string
}
)
func makePartialField (name string) partialField {
return partialField{ name : name } }
func (f partialField) Name() string {
return f.name }
func (f partialField) Bool () (bool, bool) { return false, false }
func (f partialField) String() (string, bool) { return "", false }
func (f partialField) Binary() ([]byte, bool) { return nil, false }
func (f partialField) Int () (int, bool) { return 0, false }
func (f partialField) Uint () (uint, bool) { return 0, false }
func (f partialField) Float () (float64, bool) { return 0, false }
func (f partialField) Time () (time.Time, bool) { return g.timeZero, false }
func (f partialField) Duration () (time.Duration, bool) { return 0, false }
func (f partialField) Error () (error, bool) { return nil, false }
func (f partialField) Reflect () (reflect.Value, bool) { return g.reflectZero, false }

@ -0,0 +1,51 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name defer_mode.go
// ✍️ Created by DEV
// 📅 Modified 02/05/2024
//
// 🔒 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
type (
valuerMode interface {
valuerKind() Kind
isLocal () bool
}
localValuer struct {}
deferValuer struct {}
)
func (_ localValuer) valuerKind() Kind { return 0 }
func (_ localValuer) isLocal() bool { return true }
func (_ deferValuer) valuerKind() Kind { return KindDefer }
func (_ deferValuer) isLocal() bool { return false }

@ -26,7 +26,6 @@
package aflds
import (
"active3/core/ablds"
"reflect"
"time"
)
@ -48,7 +47,7 @@ var (
ErrDuplicatedField ErrCode
ErrDistinctType ErrCode
}{
ErrInvalidKind : ErrCode("invalid-kind"),
ErrInvalidKind : ErrCode("invalid-valuerKind"),
ErrInvalidName : ErrCode("invalid-field-name"),
ErrInvalidDeferFunc : ErrCode("invalid-defer-func"),
ErrDeferNotAllowed : ErrCode("defer-field-not-allow"),
@ -65,7 +64,7 @@ var (
kindNames []string
/* 🚫 DEPRECATED
constructors map[reflect.Type]func(name string, value any) Field
constructors map[reflect.Type]func(name string, valueFn any) Field
*/
}{
@ -89,7 +88,7 @@ var (
/* 🚫 DEPRECATED : Tiene mejor rendimiento con el type switch, se descarta
constructors: map[reflect.Type] func(name string, value any) Field {
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))},
@ -151,26 +150,3 @@ var (
func buildFieldAsObject (field Field, builder ablds.ObjectBuilder) {
buildFieldAsField(field,builder)
builder.End()
}
func buildFieldAsField (field Field, builder ablds.ObjectBuilder) {
vb := builder.Field(field.Name())
switch field.Kind() {
case KindAny : vb.Any (field.Value())
case KindBool : v,_ := field.Bool(); vb.Bool(v)
case KindBinary : v,_ := field.Binary(); vb.Binary(v)
case KindString : v,_ := field.String(); vb.String(v)
case KindInt : v,_ := field.Int(); vb.Int(v)
case KindUint : v,_ := field.Uint(); vb.Uint(v)
case KindFloat : v,_ := field.Float(); vb.Float64(v)
case KindTime : v,_ := field.Time(); vb.Time(v)
case KindDuration: v,_ := field.Duration(); vb.Duration(v)
case KindError : v,_ := field.Error(); vb.Error(v)
case KindReflect : v,_ := field.Reflect(); vb.Reflect(v)
default:
vb.Any(field.Value())
}
}

@ -34,8 +34,8 @@ import (
//
// Parámetros:
// - name: El nombre del campo que se va a crear.
// - value: El valor del campo que se va a asignar.
// - kind: El tipo de campo que se va a crear, representado por un valor de la enumeración Kind.
// - valueFn: El valor del campo que se va a asignar.
// - valuerKind: El tipo de campo que se va a crear, representado por un valor de la enumeración Kind.
// Devuelve:
// - Field: El campo creado con el nombre, valor y tipo especificados.
// Pánico:
@ -57,7 +57,7 @@ func Create (name string, value any, kind Kind) Field {
case KindError : return NewFieldError (name,value.(error))
case KindReflect : return NewFieldReflect(name,value.(reflect.Value))
//Defer Fields
//valuerKind Fields
case KindDefer,
KindDeferAny : return NewDFieldAny (name,value.(func()any))
case KindDeferBool : return NewDFieldBool (name,value.(func()bool))
@ -85,7 +85,7 @@ func Create (name string, value any, kind Kind) Field {
//
// Parámetros:
// - name: El nombre del campo que se va a crear.
// - value: El valor del campo que se va a asignar.
// - valueFn: El valor del campo que se va a asignar.
// Devuelve:
// - Field: El campo creado con el nombre y valor especificados.
func CreateFromValue(name string, value any) Field {
@ -172,7 +172,7 @@ func CreateFromValue(name string, value any) Field {
// Si el valor es una función, el tipo Kind resultante tendrá la bandera KindDefer para indicar que es una función deferida.
//
// Parámetros:
// - value: El valor del cual se determinará el tipo Kind.
// - valueFn: El valor del cual se determinará el tipo Kind.
// Devuelve:
// - Kind: El tipo Kind correspondiente al valor proporcionado.
func TypeToKind(value any) Kind {

@ -23,6 +23,8 @@
package aflds
import "ablds"
type (
Field interface {
@ -34,3 +36,35 @@ type (
}
)
func FieldAsBuildable (field Field) ablds.BuildFnc {
return func (b ablds.Builder) {
buildFieldAsObject(field,b)
}
}
func buildFieldAsObject (field Field, builder ablds.Builder) {
builder.Object(func(ob ablds.ObjectBuilder){
buildFieldAsField(field,ob)
})
}
func buildFieldAsField (field Field, obuilder ablds.ObjectBuilder) {
vb := obuilder.Field(field.Name())
switch field.Kind() {
case KindAny : vb.Any (field.Value())
case KindBool : v,_ := field.Bool(); vb.Bool(v)
case KindBinary : v,_ := field.Binary(); vb.Binary(v)
case KindString : v,_ := field.String(); vb.String(v)
case KindInt : v,_ := field.Int(); vb.Int(v)
case KindUint : v,_ := field.Uint(); vb.Uint(v)
case KindFloat : v,_ := field.Float(); vb.Float64(v)
case KindTime : v,_ := field.Time(); vb.Time(v)
case KindDuration: v,_ := field.Duration(); vb.Duration(v)
case KindError : v,_ := field.Error(); vb.Error(v)
case KindReflect : v,_ := field.Reflect(); vb.Reflect(v)
default:
vb.Any(field.Value())
}
}

@ -24,6 +24,7 @@
package aflds
import (
"ablds"
"reflect"
"time"
)
@ -32,7 +33,9 @@ type (
FieldAny struct {
partialField
value any
valuerMode
value *any
valueFn func() any
}
)
@ -40,37 +43,51 @@ type (
func NewFieldAny (name string, value any) *FieldAny {
return &FieldAny{
partialField : makePartialField(name),
value : value } }
valuerMode : localValuer{},
value : &value } }
func (_ FieldAny) Kind() Kind {
return KindAny }
func NewDFieldAny (name string, valueFn func() any) *FieldAny {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldAny{
partialField: makePartialField(name),
valuerMode: deferValuer{},
valueFn : valueFn,
}
}
func (f FieldAny) Value() any {
return f.value }
func (f FieldAny) Kind() Kind {
return KindAny | f.valuerKind() }
func (f FieldAny) Value() any {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (f FieldAny) Bool () (bool,bool) {
v,ok := f.value.(bool)
v,ok := f.Value().(bool)
return v,ok
}
func (f FieldAny) Binary () ([]byte,bool) {
v, ok := f.value.([]byte)
v, ok := f.Value().([]byte)
return v, ok
}
func (f FieldAny) String () (string,bool) {
v,ok := f.value.(string)
v,ok := f.Value().(string)
return v,ok
}
func (f FieldAny) Int () (int,bool) {
switch t := f.value.(type) {
switch t := f.Value().(type) {
case int : return t,true
case int8 : return int(t),true
case int16: return int(t),true
@ -81,7 +98,7 @@ func (f FieldAny) Int () (int,bool) {
}
func (f FieldAny) Uint () (uint,bool) {
switch t := f.value.(type) {
switch t := f.Value().(type) {
case uint : return t,true
case uint8 : return uint(t),true
case uint16: return uint(t),true
@ -92,10 +109,11 @@ func (f FieldAny) Uint () (uint,bool) {
}
func (f FieldAny) Float () (float64,bool) {
v, ok := f.value.(float64)
vl := f.Value()
v, ok := vl.(float64)
if !ok {
var f32 float32
if f32,ok = f.value.(float32); ok {
if f32,ok = vl.(float32); ok {
v = float64(f32)
}
}
@ -104,25 +122,33 @@ func (f FieldAny) Float () (float64,bool) {
func (f FieldAny) Date () (time.Time,bool) {
v, ok := f.value.(time.Time)
v, ok := f.Value().(time.Time)
return v, ok
}
func (f FieldAny) Time () (time.Time,bool) {
v, ok := f.value.(time.Time)
v, ok := f.Value().(time.Time)
return v, ok
}
func (f FieldAny) Error () (error,bool) {
v, ok := f.value.(error)
v, ok := f.Value().(error)
return v, ok
}
func (f FieldAny) Reflect () (reflect.Value,bool) {
v, ok := f.value.(reflect.Value)
v, ok := f.Value().(reflect.Value)
return v, ok
}
func (f FieldAny) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Any(f.Value()) }) }

@ -23,31 +23,56 @@
package aflds
import "ablds"
type (
FieldBinary struct {
partialField
value []byte
valuerMode
value *[]byte
valueFn func()[]byte
}
)
func NewFieldBinary (name string, value []byte) *FieldBinary {
return &FieldBinary{
partialField: makePartialField(name),
value : value } }
valuerMode: localValuer{},
value: &value } }
func NewDFieldBinary (name string, valueFn func() []byte) *FieldBinary {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldBinary {
partialField: makePartialField(name),
valuerMode: deferValuer{},
valueFn : valueFn,
}
}
func (f FieldBinary) getValue() []byte {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (_ FieldBinary) Kind () Kind {
return KindBinary }
func (f FieldBinary) Kind () Kind {
return KindBinary | f.valuerKind() }
func (f FieldBinary) Value() any {
return f.value }
return f.getValue()
}
func (f FieldBinary) Binary() ([]byte,bool) {
return f.value,true }
return f.getValue(),true }
func (f FieldBinary) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Binary(f.getValue()) }) }

@ -23,30 +23,57 @@
package aflds
import "ablds"
type (
FieldBool struct {
partialField
value bool
valuerMode
value *bool
valueFn func() bool
}
)
func NewFieldBool (name string, value bool) *FieldBool {
return &FieldBool{
partialField: makePartialField(name),
value : value } }
valuerMode: localValuer{},
value : &value } }
func NewDFieldBool (name string, valueFn func() bool) *FieldBool {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldBool{
partialField: makePartialField(name),
valuerMode: deferValuer{},
valueFn : valueFn,
}
}
func (f FieldBool) getValue() bool {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (_ FieldBool) Kind () Kind {
return KindBool }
func (f FieldBool) Kind () Kind {
return KindBool | f.valuerKind() }
func (f FieldBool) Value() any {
return f.value }
return f.valueFn
}
func (f FieldBool) Bool() (bool,bool) {
return f.value,true }
return f.valueFn(),true }
func (f FieldBool) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Bool(f.getValue()) }) }

@ -23,29 +23,61 @@
package aflds
import "time"
import (
"ablds"
"time"
)
type (
FieldDuration struct {
partialField
value time.Duration
valuerMode
value *time.Duration
valueFn func () time.Duration
}
)
func NewFieldDuration (name string, value time.Duration) *FieldDuration {
return &FieldDuration{
partialField: makePartialField(name),
value : value } }
valuerMode: localValuer{},
value : &value } }
func NewDFieldDuration (name string, valueFn func() time.Duration) *FieldDuration {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldDuration{
partialField: makePartialField(name),
valuerMode: deferValuer{},
valueFn : valueFn,
}
}
func (f FieldDuration) getValue() time.Duration {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (_ FieldDuration) Kind () Kind {
return KindDuration }
func (f FieldDuration) Kind () Kind {
return KindDuration | f.valuerKind() }
func (f FieldDuration) Value() any {
return f.value }
return f.getValue()
}
func (f FieldDuration) Duration() (time.Duration,bool) {
return f.value,true }
return f.getValue(),true }
func (f FieldDuration) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Duration(f.getValue()) }) }

@ -23,13 +23,17 @@
package aflds
import (
"ablds"
)
type (
FieldError struct {
partialField
value error
valuerMode
value *error
valueFn func() error
}
)
@ -37,16 +41,42 @@ type (
func NewFieldError (name string, value error) *FieldError {
return &FieldError{
partialField: makePartialField(name),
value : value } }
valuerMode: localValuer{},
value : &value }}
func NewDFieldError (name string, valueFn func() error) *FieldError {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldError{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn,
}
}
func (f FieldError) getValue() error {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (_ FieldError) Kind () Kind {
return KindError }
func (f FieldError) Kind () Kind {
return KindError | f.valuerKind() }
func (f FieldError) Value() any {
return f.value }
return f.getValue()
}
func (f FieldError) Error() (error,bool) {
return f.value,true }
return f.getValue(),true }
func (f FieldError) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Error(f.getValue()) }) }

@ -23,32 +23,56 @@
package aflds
import "ablds"
type (
FieldFloat struct {
partialField
value float64
valuerMode
value *float64
valueFn func() float64
}
)
func NewFieldFloat (name string, value float64) *FieldFloat {
return &FieldFloat{
partialField: makePartialField(name),
value : value } }
valuerMode : localValuer{},
value : &value } }
func NewDFieldFloat (name string, valueFn func()float64) *FieldFloat {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldFloat{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn } }
func (f FieldFloat) getValue() float64 {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (_ FieldFloat) Kind () Kind {
return KindFloat }
func (f FieldFloat) Value() any {
return f.value }
func (f FieldFloat) Kind () Kind {
return KindFloat | f.valuerKind() }
func (f FieldFloat) Value() any {
return f.getValue()
}
func (f FieldFloat) Float() (float64,bool) {
return f.value,true }
return f.valueFn(),true }
func (f FieldFloat) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Float64(f.getValue())
})
}

@ -23,39 +23,60 @@
package aflds
import "active3/core/ablds"
import "ablds"
type (
FieldInt struct {
partialField
value int
valuerMode
value *int
valueFn func()int
}
)
func NewFieldInt (name string, value int) *FieldInt {
return &FieldInt{
partialField: makePartialField(name),
value : value } }
valuerMode : localValuer{},
value : &value } }
func NewDFieldInt (name string, valueFn func()int) *FieldInt {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldInt{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn,
}
}
func (_ FieldInt) Kind () Kind {
return KindInt }
func (f FieldInt) getValue() int {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (f FieldInt) Kind () Kind {
return KindInt | f.valuerKind() }
func (f FieldInt) Value() any {
return f.value }
return f.getValue() }
func (f FieldInt) Int() (int,bool) {
return f.value,true }
return f.getValue(),true }
func (f FieldInt) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Int(f.value)
b.End()
})
}
b.Field(f.name).Int(f.getValue()) }) }

@ -23,30 +23,58 @@
package aflds
import "reflect"
import (
"ablds"
"reflect"
)
type (
FieldReflect struct {
partialField
value reflect.Value
valuerMode
value *reflect.Value
valueFn func() reflect.Value
}
)
func NewFieldReflect (name string, value reflect.Value) *FieldReflect {
return &FieldReflect{
partialField: makePartialField(name),
value : value } }
valuerMode : localValuer{},
value : &value } }
func NewDFieldReflect (name string, valueFn func()reflect.Value) *FieldReflect {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldReflect{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn ,
}
}
func (_ FieldReflect) Kind () Kind {
return KindReflect }
func (f FieldReflect) getValue() reflect.Value {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (f FieldReflect) Kind () Kind {
return KindReflect | f.valuerKind() }
func (f FieldReflect) Value() any {
return f.value }
return f.getValue() }
func (f FieldReflect) Reflect() (reflect.Value,bool) {
return f.value,true }
return f.getValue(),true }
func (f FieldReflect) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Reflect(f.getValue()) }) }

@ -23,33 +23,61 @@
package aflds
import (
"ablds"
)
type (
FieldString struct {
partialField
value string
valuerMode
value *string
valueFn func() string
}
)
func NewFieldString (name string, value string) *FieldString {
return &FieldString{
partialField: makePartialField(name),
value : value } }
valuerMode: localValuer{},
value: &value,
}
}
func NewDFieldString (name string, valueFn func()string) *FieldString {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldString{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn ,
}
}
func (f FieldString) getValue() string {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (_ FieldString) Kind () Kind {
return KindString }
func (f FieldString) Kind () Kind {
return KindString | f.valuerKind() }
func (f FieldString) Value() any {
return f.value }
return f.getValue() }
func (f FieldString) String() (string,bool) {
return f.value,true }
return f.getValue(),true }
func (f FieldString) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).String(f.getValue())
})
}

@ -23,29 +23,59 @@
package aflds
import "time"
import (
"ablds"
"time"
)
type (
FieldTime struct {
partialField
value time.Time
valuerMode
value *time.Time
valueFn func() time.Time
}
)
func NewFieldTime (name string, value time.Time) *FieldTime {
return &FieldTime{
partialField: makePartialField(name),
value : value } }
valuerMode: localValuer{},
value: &value } }
func NewDFieldTime(name string, valueFn func()time.Time) *FieldTime {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldTime{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn ,
}
}
func (_ FieldTime) Kind () Kind {
return KindTime }
func (f FieldTime) getValue() time.Time {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (f FieldTime) Kind () Kind {
return KindTime | f.valuerKind() }
func (f FieldTime) Value() any {
return f.value }
return f.getValue() }
func (f FieldTime) Time() (time.Time,bool) {
return f.value,true }
return f.getValue(),true }
func (f FieldTime) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Time(f.getValue()) }) }

@ -23,33 +23,59 @@
package aflds
import (
"ablds"
)
type (
FieldUint struct {
partialField
value uint
valuerMode
value *uint
valueFn func() uint
}
)
func NewFieldUint (name string, value uint) *FieldUint {
return &FieldUint{
partialField: makePartialField(name),
value : value } }
valuerMode: localValuer{},
value: &value } }
func NewDFieldUint (name string, valueFn func()uint) *FieldUint {
if valueFn == nil {
panic(G.ErrInvalidDeferFunc)
}
return &FieldUint{
partialField: makePartialField(name),
valuerMode : deferValuer{},
valueFn : valueFn ,
}
}
func (f FieldUint) getValue() uint {
if f.isLocal() {
return *f.value
}
return f.valueFn()
}
func (_ FieldUint) Kind () Kind {
return KindInt }
func (f FieldUint) Kind () Kind {
return KindInt | f.valuerKind() }
func (f FieldUint) Value() any {
return f.value }
return f.getValue() }
func (f FieldUint) Uint() (uint,bool) {
return f.value,true }
return f.getValue(),true }
func (f FieldUint) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Uint(f.getValue()) }) }

@ -24,7 +24,7 @@
package aflds
import (
"active3/core/ablds"
"ablds"
"sort"
)
@ -137,10 +137,7 @@ func (f Fields) indexOf(name string) int {
func (f Fields) Build (builder ablds.Builder) {
builder.List(func(lb ablds.ListBuilder) {
for _,fl := range f {
lb.Item().Object(func (ob ablds.ObjectBuilder){
buildFieldAsObject(fl,ob)
})
buildFieldAsObject(fl,lb.Item())
}
lb.End()
})
}

@ -23,7 +23,10 @@
package aflds
import "sort"
import (
"ablds"
"sort"
)
type (
@ -184,6 +187,16 @@ func (f *FieldsObject) Sort() {
func (f *FieldsObject) Build (builder ablds.Builder) {
builder.Object(func(ob ablds.ObjectBuilder) {
for _,fl := range f.fields {
buildFieldAsField(fl,ob)
}
})
}
func FieldsObjectWithAtts (set FieldsAtt) FieldsObjectFnc {
return func(f *FieldsObject) error {

@ -47,11 +47,12 @@ func makePartialField (name string) partialField {
return partialField{ name : name } }
func (f partialField) Name() string {
return f.name }
func (f partialField) Name() string {
return f.name }
func (f partialField) Bool () (bool, bool) { return false, false }

@ -2,7 +2,7 @@
// ℹ️ Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name ender.go
// File name defer_mode.go
// ✍️ Created by DEV
// 📅 Modified 02/05/2024
//
@ -22,18 +22,30 @@
// limitations under the License.
// ------------------------------------------------------------------------
package ablds
package aflds
type (
Ender interface {
type (
End ()
valuerMode interface {
valuerKind() Kind
isLocal () bool
}
localValuer struct {}
deferValuer struct {}
)
func (_ localValuer) valuerKind() Kind { return 0 }
func (_ localValuer) isLocal() bool { return true }
func (_ deferValuer) valuerKind() Kind { return KindDefer }
func (_ deferValuer) isLocal() bool { return false }

@ -0,0 +1,152 @@
// ------------------------------------------------------------------------
// ℹ️ 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 fields
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-kind"),
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, value 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, value 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))},
},
*/
}
)

@ -21,9 +21,10 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import (
"ablds"
"reflect"
"time"
)
@ -134,3 +135,7 @@ func (f DFieldAny) Reflect () (reflect.Value,bool) {
}
func (f DFieldAny) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Any(f.valueFn()) }) }

@ -21,10 +21,9 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import "ablds"
type (
@ -53,3 +52,8 @@ func (f DFieldBinary) Value() any {
func (f DFieldBinary) Binary() ([]byte,bool) {
return f.valueFn(),true }
func (f DFieldBinary) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Binary(f.valueFn()) }) }

@ -21,9 +21,9 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import "ablds"
type (
@ -54,3 +54,6 @@ func (f DFieldBool) Value() any {
func (f DFieldBool) Bool() (bool,bool) {
return f.valueFn(),true }
func (f DFieldBool) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Bool(f.valueFn()) }) }

@ -21,9 +21,12 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import "time"
import (
"ablds"
"time"
)
type (
@ -52,3 +55,8 @@ func (f DFieldDuration) Value() any {
func (f DFieldDuration) Duration() (time.Duration,bool) {
return f.valueFn(),true }
func (f DFieldDuration) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Duration(f.valueFn()) }) }

@ -21,9 +21,9 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import "ablds"
type (
@ -53,3 +53,8 @@ func (f DFieldError) Value() any {
func (f DFieldError) Error() (error,bool) {
return f.valueFn(),true }
func (f DFieldError) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Error(f.valueFn()) }) }

@ -21,10 +21,9 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import "ablds"
type (
@ -55,3 +54,6 @@ func (f DFieldFloat) Float() (float64,bool) {
return f.valueFn(),true }
func (f DFieldFloat) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Float64(f.valueFn()) }) }

@ -21,9 +21,9 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import "ablds"
type (
@ -54,5 +54,7 @@ func (f DFieldInt) Int() (int,bool) {
return f.valueFn(),true }
func (f DFieldInt) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Int(f.valueFn()) }) }

@ -21,9 +21,12 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import "reflect"
import (
"ablds"
"reflect"
)
type (
@ -52,3 +55,8 @@ func (f DFieldReflect) Value() any {
func (f DFieldReflect) Reflect() (reflect.Value,bool) {
return f.valueFn(),true }
func (f DFieldReflect) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Reflect(f.valueFn()) }) }

@ -21,9 +21,9 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import "ablds"
type (
@ -56,4 +56,7 @@ func (f DFieldString) String() (string,bool) {
func (f DFieldString) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).String(f.valueFn()) }) }

@ -21,9 +21,12 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import "time"
import (
"ablds"
"time"
)
type (
@ -52,3 +55,9 @@ func (f DFieldTime) Value() any {
func (f DFieldTime) Time() (time.Time,bool) {
return f.valueFn(),true }
func (f DFieldTime) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Time(f.valueFn()) }) }

@ -21,9 +21,9 @@
// limitations under the License.
// ------------------------------------------------------------------------
package aflds
package fields
import "ablds"
type (
@ -54,4 +54,7 @@ func (f DFieldUint) Uint () (uint,bool) {
func (f DFieldUint) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Uint(f.valueFn()) }) }

@ -0,0 +1,46 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name err_code.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
type (
ErrCode string
)
func (e ErrCode) Error () string {
return string(e) }
func (e ErrCode) Code () string {
return string(e) }
func (_ ErrCode) Unwrap() error {
return nil }
func (_ ErrCode) UnwrapAll() []error {
return nil }

@ -0,0 +1,246 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name factory.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import (
"reflect"
"time"
)
// Create es un método que crea y devuelve un nuevo campo con el nombre, valor y tipo especificados.
// Este método es utilizado para crear campos de diferentes tipos según el valor del tipo Kind proporcionado.
// Si el tipo Kind es KindAny, el campo se crea utilizando el valor y su tipo se infiere automáticamente.
//
// Parámetros:
// - name: El nombre del campo que se va a crear.
// - value: El valor del campo que se va a asignar.
// - kind: El tipo de campo que se va a crear, representado por un valor de la enumeración Kind.
// Devuelve:
// - Field: El campo creado con el nombre, valor y tipo especificados.
// Pánico:
// - Si se proporciona un tipo de Kind inválido, el método entra en un estado de pánico y devuelve un error ErrInvalidKind.
func Create (name string, value any, kind Kind) Field {
if kind == 0 {
return CreateFromValue(name,value)
}
switch kind {
case KindAny : return NewFieldAny (name,value)
case KindBool : return NewFieldBool (name,value.(bool))
case KindBinary : return NewFieldBinary(name,value.([]byte))
case KindString : return NewFieldString(name,value.(string))
case KindInt : return NewFieldInt (name,value.(int))
case KindUint : return NewFieldUint (name,value.(uint))
case KindFloat : return NewFieldFloat (name,value.(float64))
case KindTime : return NewFieldTime (name,value.(time.Time))
case KindDuration:return NewFieldDuration(name,value.(time.Duration))
case KindError : return NewFieldError (name,value.(error))
case KindReflect : return NewFieldReflect(name,value.(reflect.Value))
//kindDefer Fields
case KindDefer,
KindDeferAny : return NewDFieldAny (name,value.(func()any))
case KindDeferBool : return NewDFieldBool (name,value.(func()bool))
case KindDeferString : return NewDFieldString(name,value.(func()string))
case KindDeferBinary : return NewDFieldBinary(name,value.(func()[]byte))
case KindDeferInt : return NewDFieldInt (name,value.(func()int))
case KindDeferUint : return NewDFieldUint (name,value.(func()uint))
case KindDeferFloat : return NewDFieldFloat (name,value.(func()float64))
case KindDeferTime : return NewDFieldTime (name,value.(func()time.Time))
case KindDeferDuration:return NewDFieldDuration (name,value.(func()time.Duration))
case KindDeferError : return NewDFieldError (name,value.(func()error))
case KindDeferReflect :return NewDFieldReflect(name,value.(func()reflect.Value))
default:
panic(G.ErrInvalidKind)
}
}
// CreateFromValue es un método que crea y devuelve un nuevo campo basado en el valor proporcionado.
// Examina el tipo del valor y crea un campo correspondiente, asignando el nombre especificado.
// Si el tipo del valor no coincide con ninguno de los tipos predefinidos, se crea un campo genérico utilizando el tipo KindAny.
//
// Parámetros:
// - name: El nombre del campo que se va a crear.
// - value: El valor del campo que se va a asignar.
// Devuelve:
// - Field: El campo creado con el nombre y valor especificados.
func CreateFromValue(name string, value any) Field {
switch t := value.(type) {
case bool : return NewFieldBool (name,t)
case []byte : return NewFieldBinary (name,t)
case string : return NewFieldString (name,t)
case int : return NewFieldInt (name,t)
case int8 : return NewFieldInt (name,int(t))
case int16 : return NewFieldInt (name,int(t))
case int32 : return NewFieldInt (name,int(t))
case int64 : return NewFieldInt (name,int(t))
case uint : return NewFieldUint (name,t)
case uint8 : return NewFieldUint (name,uint(t))
case uint16 : return NewFieldUint (name,uint(t))
case uint32 : return NewFieldUint (name,uint(t))
case uint64 : return NewFieldUint (name,uint(t))
case uintptr: return NewFieldUint (name,uint(t))
case float64: return NewFieldFloat(name,t)
case float32: return NewFieldFloat(name,float64(t))
case error : return NewFieldError(name,t)
case time.Time:
return NewFieldTime (name,t)
case time.Duration:
return NewFieldDuration (name,t)
case reflect.Value :
return NewFieldReflect(name,t)
case func() any : return NewDFieldAny (name,t)
case func() bool : return NewDFieldBool(name,t)
case func() []byte : return NewDFieldBinary(name,t)
case func() string : return NewDFieldString(name,t)
case func() int : return NewDFieldInt (name,t)
case func() int8 : return NewDFieldInt (name,func() int { return int(t()) })
case func() int16 : return NewDFieldInt (name,func() int { return int(t()) })
case func() int32 : return NewDFieldInt (name,func() int { return int(t()) })
case func() int64 : return NewDFieldInt (name,func() int { return int(t()) })
case func() uint : return NewDFieldUint(name,t)
case func() uint8 : return NewDFieldUint(name,func() uint { return uint(t()) })
case func() uint16 : return NewDFieldUint(name,func() uint { return uint(t()) })
case func() uint32 : return NewDFieldUint(name,func() uint { return uint(t()) })
case func() uint64 : return NewDFieldUint(name,func() uint { return uint(t()) })
case func() uintptr: return NewDFieldUint(name,func() uint { return uint(t()) })
case func() float64: return NewDFieldFloat(name,t)
case func() float32: return NewDFieldFloat(name,func() float64 { return float64(t()) })
case func() error : return NewDFieldError(name,t)
case func() time.Time :
return NewDFieldTime(name,t)
case func() time.Duration :
return NewDFieldDuration(name,t)
case func() reflect.Value :
return NewDFieldReflect(name,t)
default:
if value != nil {
rv := reflect.ValueOf(value)
if rv.Kind() == reflect.Func {
tp := rv.Type()
if tp.NumIn() == 0 && tp.NumOut() == 1 {
return NewDFieldAny(name, func() any {
return rv.Call(nil)[0].Interface()
})
}
}
}
return NewFieldAny(name,value)
}
}
// TypeToKind es una función que determina el tipo de Kind correspondiente al valor proporcionado.
// Examina el tipo del valor y devuelve un tipo Kind adecuado que representa el tipo del valor.
// Si el valor es una función, el tipo Kind resultante tendrá la bandera KindDefer para indicar que es una función deferida.
//
// Parámetros:
// - value: El valor del cual se determinará el tipo Kind.
// Devuelve:
// - Kind: El tipo Kind correspondiente al valor proporcionado.
func TypeToKind(value any) Kind {
switch value.(type) {
case bool:
return KindAny
case []byte :
return KindBinary
case string :
return KindString
case int,
int8,
int16,
int32,
int64 :
return KindInt
case uint,
uint8,
uint16,
uint32,
uint64,
uintptr : return KindUint
case float64,
float32:
return KindFloat
case error :
return KindError
case time.Time:
return KindTime
case reflect.Value:
return KindReflect
case func() any :
return KindAny|KindDefer
case func() bool :
return KindBool|KindDefer
case func() []byte :
return KindBinary|KindDefer
case func() string :
return KindString|KindDefer
case func() int,
func() int8,
func() int16,
func() int32,
func() int64 :
return KindInt|KindDefer
case func() uint,
func() uint8,
func() uint16,
func() uint32,
func() uint64,
func() uintptr :
return KindInt|KindDefer
case func() float64,
func() float32 :
return KindFloat|KindDefer
case func() error :
return KindError|KindDefer
case func() time.Time:
return KindTime|KindDefer
case func() reflect.Value:
return KindReflect|KindDefer
default:
rt := reflect.TypeOf(value)
if rt.Kind() == reflect.Func && rt.NumIn() == 0 && rt.NumOut() == 1 {
return KindAny|KindDefer
}
return KindAny
}
}

@ -0,0 +1,70 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import "ablds"
type (
Field interface {
NativeResolver
Kind () Kind
Name () string
Value() any
}
)
func FieldAsBuildable (field Field) ablds.BuildFnc {
return func (b ablds.Builder) {
buildFieldAsObject(field,b)
}
}
func buildFieldAsObject (field Field, builder ablds.Builder) {
builder.Object(func(ob ablds.ObjectBuilder){
buildFieldAsField(field,ob)
})
}
func buildFieldAsField (field Field, obuilder ablds.ObjectBuilder) {
vb := obuilder.Field(field.Name())
switch field.Kind() {
case KindAny : vb.Any (field.Value())
case KindBool : v,_ := field.Bool(); vb.Bool(v)
case KindBinary : v,_ := field.Binary(); vb.Binary(v)
case KindString : v,_ := field.String(); vb.String(v)
case KindInt : v,_ := field.Int(); vb.Int(v)
case KindUint : v,_ := field.Uint(); vb.Uint(v)
case KindFloat : v,_ := field.Float(); vb.Float64(v)
case KindTime : v,_ := field.Time(); vb.Time(v)
case KindDuration: v,_ := field.Duration(); vb.Duration(v)
case KindError : v,_ := field.Error(); vb.Error(v)
case KindReflect : v,_ := field.Reflect(); vb.Reflect(v)
default:
vb.Any(field.Value())
}
}

@ -0,0 +1,133 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_any.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import (
"ablds"
"reflect"
"time"
)
type (
FieldAny struct {
partialField
value any
}
)
func NewFieldAny (name string, value any) *FieldAny {
return &FieldAny{
partialField : makePartialField(name),
value : value } }
func (_ FieldAny) Kind() Kind {
return KindAny }
func (f FieldAny) Value() any {
return f.value }
func (f FieldAny) Bool () (bool,bool) {
v,ok := f.value.(bool)
return v,ok
}
func (f FieldAny) Binary () ([]byte,bool) {
v, ok := f.value.([]byte)
return v, ok
}
func (f FieldAny) String () (string,bool) {
v,ok := f.value.(string)
return v,ok
}
func (f FieldAny) Int () (int,bool) {
switch t := f.value.(type) {
case int : return t,true
case int8 : return int(t),true
case int16: return int(t),true
case int32: return int(t),true
case int64: return int(t),true
default : return 0,false
}
}
func (f FieldAny) Uint () (uint,bool) {
switch t := f.value.(type) {
case uint : return t,true
case uint8 : return uint(t),true
case uint16: return uint(t),true
case uint32: return uint(t),true
case uint64: return uint(t),true
default : return 0,false
}
}
func (f FieldAny) Float () (float64,bool) {
v, ok := f.value.(float64)
if !ok {
var f32 float32
if f32,ok = f.value.(float32); ok {
v = float64(f32)
}
}
return v, ok
}
func (f FieldAny) Date () (time.Time,bool) {
v, ok := f.value.(time.Time)
return v, ok
}
func (f FieldAny) Time () (time.Time,bool) {
v, ok := f.value.(time.Time)
return v, ok
}
func (f FieldAny) Error () (error,bool) {
v, ok := f.value.(error)
return v, ok
}
func (f FieldAny) Reflect () (reflect.Value,bool) {
v, ok := f.value.(reflect.Value)
return v, ok
}
func (f FieldAny) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Any(f.value) }) }

@ -0,0 +1,56 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_binary.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import "ablds"
type (
FieldBinary struct {
partialField
value []byte
}
)
func NewFieldBinary (name string, value []byte) *FieldBinary {
return &FieldBinary{
partialField: makePartialField(name),
value : value } }
func (_ FieldBinary) Kind () Kind {
return KindBinary }
func (f FieldBinary) Value() any {
return f.value }
func (f FieldBinary) Binary() ([]byte,bool) {
return f.value,true }
func (f FieldBinary) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Binary(f.value) }) }

@ -0,0 +1,56 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_bool.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import "ablds"
type (
FieldBool struct {
partialField
value bool
}
)
func NewFieldBool (name string, value bool) *FieldBool {
return &FieldBool{
partialField: makePartialField(name),
value : value } }
func (_ FieldBool) Kind () Kind {
return KindBool }
func (f FieldBool) Value() any {
return f.value }
func (f FieldBool) Bool() (bool,bool) {
return f.value,true }
func (f FieldBool) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Bool(f.value) }) }

@ -0,0 +1,59 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_time.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import (
"ablds"
"time"
)
type (
FieldDuration struct {
partialField
value time.Duration
}
)
func NewFieldDuration (name string, value time.Duration) *FieldDuration {
return &FieldDuration{
partialField: makePartialField(name),
value : value } }
func (_ FieldDuration) Kind () Kind {
return KindDuration }
func (f FieldDuration) Value() any {
return f.value }
func (f FieldDuration) Duration() (time.Duration,bool) {
return f.value,true }
func (f FieldDuration) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Duration(f.value) }) }

@ -0,0 +1,57 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_error.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import "ablds"
type (
FieldError struct {
partialField
value error
}
)
func NewFieldError (name string, value error) *FieldError {
return &FieldError{
partialField: makePartialField(name),
value : value } }
func (_ FieldError) Kind () Kind {
return KindError }
func (f FieldError) Value() any {
return f.value }
func (f FieldError) Error() (error,bool) {
return f.value,true }
func (f FieldError) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Error(f.value) }) }

@ -0,0 +1,56 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_float.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import "ablds"
type (
FieldFloat struct {
partialField
value float64
}
)
func NewFieldFloat (name string, value float64) *FieldFloat {
return &FieldFloat{
partialField: makePartialField(name),
value : value } }
func (_ FieldFloat) Kind () Kind {
return KindFloat }
func (f FieldFloat) Value() any {
return f.value }
func (f FieldFloat) Float() (float64,bool) {
return f.value,true }
func (f FieldFloat) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Float64(f.value) }) }

@ -0,0 +1,58 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_int.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import "ablds"
type (
FieldInt struct {
partialField
value int
}
)
func NewFieldInt (name string, value int) *FieldInt {
return &FieldInt{
partialField: makePartialField(name),
value : value } }
func (_ FieldInt) Kind () Kind {
return KindInt }
func (f FieldInt) Value() any {
return f.value }
func (f FieldInt) Int() (int,bool) {
return f.value,true }
func (f FieldInt) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Int(f.value) }) }

@ -0,0 +1,60 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_reflect.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import (
"ablds"
"reflect"
)
type (
FieldReflect struct {
partialField
value reflect.Value
}
)
func NewFieldReflect (name string, value reflect.Value) *FieldReflect {
return &FieldReflect{
partialField: makePartialField(name),
value : value } }
func (_ FieldReflect) Kind () Kind {
return KindReflect }
func (f FieldReflect) Value() any {
return f.value }
func (f FieldReflect) Reflect() (reflect.Value,bool) {
return f.value,true }
func (f FieldReflect) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Reflect(f.value) }) }

@ -0,0 +1,58 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_string.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import "ablds"
type (
FieldString struct {
partialField
value string
}
)
func NewFieldString (name string, value string) *FieldString {
return &FieldString{
partialField: makePartialField(name),
value : value } }
func (_ FieldString) Kind () Kind {
return KindString }
func (f FieldString) Value() any {
return f.value }
func (f FieldString) String() (string,bool) {
return f.value,true }
func (f FieldString) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).String(f.value) }) }

@ -0,0 +1,60 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_time.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import (
"ablds"
"time"
)
type (
FieldTime struct {
partialField
value time.Time
}
)
func NewFieldTime (name string, value time.Time) *FieldTime {
return &FieldTime{
partialField: makePartialField(name),
value : value } }
func (_ FieldTime) Kind () Kind {
return KindTime }
func (f FieldTime) Value() any {
return f.value }
func (f FieldTime) Time() (time.Time,bool) {
return f.value,true }
func (f FieldTime) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Time(f.value) }) }

@ -0,0 +1,57 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name field_unuint.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import "ablds"
type (
FieldUint struct {
partialField
value uint
}
)
func NewFieldUint (name string, value uint) *FieldUint {
return &FieldUint{
partialField: makePartialField(name),
value : value } }
func (_ FieldUint) Kind () Kind {
return KindInt }
func (f FieldUint) Value() any {
return f.value }
func (f FieldUint) Uint() (uint,bool) {
return f.value,true }
func (f FieldUint) Build (builder ablds.Builder) {
builder.Object(func(b ablds.ObjectBuilder){
b.Field(f.name).Uint(f.value) }) }

@ -0,0 +1,143 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name fields.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import (
"ablds"
"sort"
)
type (
// Fields es un tipo que representa una lista de campos y proporciona métodos
// para gestionar y manipular dicha lista.
Fields []Field
)
func (f Fields) Len () int {
return len(f) }
func (f Fields) Has (name string) bool {
return f.indexOf(name) != -1 }
func (f Fields) Kinds() Kind {
var k Kind
for _,f := range f {
k|=f.Kind()
}
return k
}
func (f Fields) Get(name string) Field {
if p := f.indexOf(name); p != -1 {
return f[p]
}
return nil
}
func (f Fields) GetAll (name string) []Field {
var ls []Field
for _,fl := range f {
if fl.Name() == name {
ls = append(ls,fl)
}
}
return ls
}
func (f Fields) Add(field Field) Fields {
if field != nil {
return append(f,field)
}
return f
}
func (f Fields) Set(field Field) Fields {
if field == nil {
return f
}
if p := f.indexOf(field.Name()); p != -1 {
return append(append(f[:p],field), f[p+1:]...)
}
return append(f,field)
}
func (f Fields) Del(name string) Fields {
if p := f.indexOf(name); p != -1 {
return append(f[:p],f[p+1:]...)
}
return f
}
func (f Fields) DelAll (name string) Fields {
l := make(Fields,0,len(f))
c := 0
for i := 0; i<len(f); i++ {
if f[i].Name() == name {
l = append(l,f[c:i]...)
c = i+1
}
}
l = append(l,f[c:]...)
return l
}
func (f Fields) Sort() {
sort.Sort(f) }
func (f Fields) Swap(i, j int) {
f[i], f[j] = f[j], f[i] }
func (f Fields) Less(i, j int) bool {
return f[i].Name() < f[j].Name() }
func (f Fields) indexOf(name string) int {
for i,f := range f {
if f.Name() == name {
return i
}
}
return -1
}
func (f Fields) Build (builder ablds.Builder) {
builder.List(func(lb ablds.ListBuilder) {
for _,fl := range f {
buildFieldAsObject(fl,lb.Item())
}
})
}

@ -0,0 +1,57 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name atts.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
const(
AttFieldsReadOnly FieldsAtt = 1 << iota
AttFieldsNotDefer
AttFieldsNotDuplicated
AttFieldSetSameKind
)
type (
// FieldsAtt representa los atributos asociados a los campos en un objeto FieldsObject
// y definen la forma en que este debe de gestionarlos y que se permite.
FieldsAtt uint8
)
func (a FieldsAtt) IsReadOnly () bool {
return a&AttFieldsReadOnly != 0 }
func (a FieldsAtt) IsNotDefer() bool {
return a&AttFieldsNotDefer != 0 }
func (a FieldsAtt) IsNotDuplicate() bool {
return a&AttFieldsNotDuplicated != 0 }
func (a FieldsAtt) IsSetSameKind () bool {
return a&AttFieldSetSameKind != 0 }

@ -0,0 +1,214 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name fieldsObject.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import (
"ablds"
"sort"
)
type (
// FieldsObject representa un objeto que contiene Fields. Este objeto proporciona métodos para gestionar y
// manipular estos campos de diversas formas, como agregar, eliminar, obtener y listar.
FieldsObject struct {
atts FieldsAtt
fields Fields
}
FieldsObjectFnc func(object *FieldsObject) error
)
func NewFieldsObject (options ...FieldsObjectFnc) (*FieldsObject,error) {
f := &FieldsObject{}
for _,o := range options {
if er := o(f); er != nil {
return nil,er
}
}
return f,nil
}
func (f *FieldsObject) Len () int {
return len(f.fields) }
func (f *FieldsObject) Has (name string) bool {
return f.fields.Has(name) }
func (f *FieldsObject) Kinds() Kind {
return f.fields.Kinds() }
func (f *FieldsObject) Get(name string) Field {
return f.fields.Get(name) }
func (f *FieldsObject) GetAll (name string) []Field {
if f.atts.IsNotDuplicate() {
f := f.fields.Get(name)
if f != nil {
return []Field{f}
}
return nil
}
return f.fields.GetAll(name)
}
func (f *FieldsObject) New(name string, value any, kind Kind) error {
return f.Add(Create(name,value,kind)) }
// Add agrega un nuevo campo al objeto FieldsObject.
// Si el objeto está configurado como de solo lectura, // devuelve un error ErrFieldsReadOnly.
// Si se especifica que no se permiten campos duplicados y se intenta agregar un // campo que ya existe con el mismo
// nombre, devuelve un error ErrDuplicatedField.
// Si se especifica que los campos deben ser del mismo tipo y se intenta agregar un campo con un tipo diferente al de
// los campos existentes con el mismo nombre, devuelve un error ErrDistinctType.
//
// Parámetros:
// - field: El campo que se va a agregar al objeto FieldsObject.
// Devuelve:
// - error: Un error, si ocurre alguno; de lo contrario, nil.
//
// Por motivos de prestaciones es recomendable usar la creación específica de cada
// campo que no la creación a través de la factoría con la llamada a New.
func (f *FieldsObject) Add(field Field) error {
if f.atts.IsReadOnly() {
return G.ErrFieldsReadOnly
}
if p := f.fields.indexOf(field.Name()); p != -1 {
if f.atts.IsNotDuplicate() {
return G.ErrDuplicatedField
}
if f.atts.IsSetSameKind() && f.fields[p].Kind() != field.Kind() {
return G.ErrDistinctType
}
}
f.fields = f.fields.Add(field)
return nil
}
// Set sustituye o añade un Field al objeto de Fields
// Si los atributos del objeto es de solo lectura, devuelve un error ErrFieldsReadOnly.
// Si los atributos del objeto no permite defers y se intenta agregar un campo defer, devuelve un error ErrDeferNotAllowed.
// Si los atributos del objeto requiere que el Field por el que se sustituye en su caso sean del mismo tipo, si se intenta
// agregar un campo de un tipo diferente, devuelve un error ErrDistinctType.
//
// Parámetros:
// - field: El campo que se agregará al objeto de campos.
// Devuelve:
// - error: Un error, si ocurre alguno; de lo contrario, nil.
func (f *FieldsObject) Set(field Field) error {
if f.atts.IsReadOnly() {
return G.ErrFieldsReadOnly
}
if f.atts.IsNotDefer() && field.Kind().IsDefer() {
return G.ErrDeferNotAllowed
}
if p := f.fields.indexOf(field.Name()); p != -1 {
if f.atts.IsSetSameKind() && field.Kind() != f.fields[p].Kind() {
return G.ErrDistinctType
}
f.fields[p]=field
} else {
f.fields = f.fields.Add(field)
}
return nil
}
func (f *FieldsObject) Del(name string) error {
if f.atts.IsReadOnly() {
return G.ErrFieldsReadOnly
}
f.fields = f.fields.Del(name)
return nil
}
// DelAll elimina todos los campos con el nombre especificado del objeto de campos.
// Si el objeto de atributos asociado a los campos es de solo lectura, devuelve un error ErrFieldsReadOnly.
// Si el nombre proporcionado está vacío, elimina todos los campos del objeto de campos.
//
// Parámetros:
// - name: El nombre del campo que se eliminará.
// Devuelve:
// - error: Un error, si ocurre alguno; de lo contrario, nil.
func (f *FieldsObject) DelAll (name string) error {
if f.atts.IsReadOnly() {
return G.ErrFieldsReadOnly
}
if len(name) == 0 {
f.fields = f.fields[:0]
return nil
}
if f.atts.IsNotDuplicate() {
f.fields = f.fields.Del(name)
return nil
}
f.fields = f.fields.DelAll(name)
return nil
}
func (f *FieldsObject) List() Fields {
return f.fields }
func (f *FieldsObject) Sort() {
if f.atts.IsReadOnly() {
return
}
sort.Sort(f.fields) }
func (f *FieldsObject) Build (builder ablds.Builder) {
builder.Object(func(ob ablds.ObjectBuilder) {
for _,fl := range f.fields {
buildFieldAsField(fl,ob)
}
})
}
func FieldsObjectWithAtts (set FieldsAtt) FieldsObjectFnc {
return func(f *FieldsObject) error {
f.atts = set
return nil } }
func FieldsObjectWithField(field Field) FieldsObjectFnc {
return func(f *FieldsObject) error {
return f.Add(field) } }
func FieldsObjectWithNew (name string, value any, kind Kind) FieldsObjectFnc {
return func(f *FieldsObject) error {
return f.New(name,value,kind) } }

@ -0,0 +1,4 @@
module fields
go 1.22

@ -0,0 +1,144 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name att.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import "math/bits"
const(
KindAny Kind = 1 << iota
KindBool
KindBinary
KindString
KindInt
KindUint
KindFloat
KindTime
KindDuration
KindError
KindReflect
KindDefer Kind = 16384
)
const(
KindDeferAny = KindDefer|KindAny
KindDeferBool = KindDefer|KindBool
KindDeferString = KindDefer|KindString
KindDeferBinary = KindDefer|KindBinary
KindDeferInt = KindDefer|KindInt
KindDeferUint = KindDefer|KindUint
KindDeferFloat = KindDefer|KindFloat
KindDeferTime = KindDefer|KindTime
KindDeferDuration = KindDefer|KindDuration
KindDeferError = KindDefer|KindError
KindDeferReflect = KindDefer|KindReflect
)
type (
Kind uint16
)
func (k Kind) IsAny() bool {
return k&KindAny != 0 }
func (k Kind) IsBool() bool {
return k&KindBool != 0 }
func (k Kind) IsInt() bool {
return k&KindInt != 0 }
func (k Kind) IsUint() bool {
return k&KindUint != 0 }
func (k Kind) IsFloat() bool {
return k&KindFloat != 0 }
func (k Kind) IsString() bool {
return k&KindString != 0 }
func (k Kind) IsTime() bool {
return k&KindTime != 0 }
func (k Kind) IsDuration() bool {
return k&KindDuration != 0 }
func (k Kind) IsBinary() bool {
return k&KindBinary != 0 }
func (k Kind) IsError() bool {
return k&KindError != 0 }
func (k Kind) IsReflect() bool {
return k&KindReflect != 0 }
func (k Kind) IsDefer() bool {
return k&KindDefer != 0 }
func (k Kind) Count () int {
return bits.OnesCount16(uint16(k)) }
func (k Kind) Kinds () []Kind {
if k == 0 {
return nil
}
var ls []Kind
c := Kind(1)
for i:=0; i< kindBits; i++ {
c = 1 << i
if c&k != 0 {
ls = append(ls,c)
}
}
return ls
}
func (k Kind) KindNames () []string {
if k==0 {
return []string{""}
}
var ls []string
c := Kind(1)
for i:=0; i< kindBits; i++ {
c = 1 << i
if c&k != 0 {
ls = append(ls, g.kindNames[i])
}
}
return ls
}

@ -0,0 +1,78 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name value_resolver.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import (
"reflect"
"time"
)
type (
// NativeResolver es una interfaz que define métodos para resolver
// y obtener valores nativos de diferentes tipos, junto con un indicador
// de éxito para indicar si la resolución fue exitosa o no.
NativeResolver interface {
// Bool intenta resolver y devolver el valor como un booleano.
// Retorna el valor booleano y un indicador de éxito.
Bool() (bool, bool)
// Binary intenta resolver y devolver el valor como un slice de bytes.
// Retorna el slice de bytes y un indicador de éxito.
Binary() ([]byte, bool)
// String intenta resolver y devolver el valor como una cadena de texto.
// Retorna la cadena de texto y un indicador de éxito.
String() (string, bool)
// Int intenta resolver y devolver el valor como un entero.
// Retorna el entero y un indicador de éxito.
Int() (int, bool)
// Uint intenta resolver y devolver el valor como un entero sin signo.
// Retorna el entero sin signo y un indicador de éxito.
Uint() (uint, bool)
// Float intenta resolver y devolver el valor como un número flotante de punto flotante de 64 bits.
// Retorna el número flotante y un indicador de éxito.
Float() (float64, bool)
// Time intenta resolver y devolver el valor como una marca de tiempo.
// Retorna la marca de tiempo y un indicador de éxito.
Time() (time.Time, bool)
// Duration intenta resolver y devolver el valor como una duración de tiempo
// Retorna la duración y un indicador de éxito.
Duration() (time.Duration, bool)
// Error intenta resolver y devolver el valor como un error.
// Retorna el error y un indicador de éxito.
Error() (error, bool)
// Reflect intenta resolver y devolver el valor como un reflect.Value.
// Retorna el reflect.Value y un indicador de éxito.
Reflect() (reflect.Value, bool)
}
)

@ -0,0 +1,79 @@
// ------------------------------------------------------------------------
// ℹ️ Project active3
// Active Thing (activething.com) git.activething.com/go
//
// File name partial_field.go
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// ------------------------------------------------------------------------
// 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 fields
import (
"reflect"
"time"
)
type (
// partialField representa un Field parcialmente definido con solo el nombre.
// Implementa el interface NativeResolver de forma nula para proporcionar valores
// predeterminados para los tipos de datos comunes. Cuando un objeto Field
// sobrescribe alguno de estos métodos, se produce shadowing, lo que significa
// que la implementación en Field prevalecerá sobre la implementación nula de
// partialField.
partialField struct {
name string
}
)
func makePartialField (name string) partialField {
return partialField{ name : name } }
func (f partialField) Name() string {
return f.name }
func (f partialField) Bool () (bool, bool) { return false, false }
func (f partialField) String() (string, bool) { return "", false }
func (f partialField) Binary() ([]byte, bool) { return nil, false }
func (f partialField) Int () (int, bool) { return 0, false }
func (f partialField) Uint () (uint, bool) { return 0, false }
func (f partialField) Float () (float64, bool) { return 0, false }
func (f partialField) Time () (time.Time, bool) { return g.timeZero, false }
func (f partialField) Duration () (time.Duration, bool) { return 0, false }
func (f partialField) Error () (error, bool) { return nil, false }
func (f partialField) Reflect () (reflect.Value, bool) { return g.reflectZero, false }

@ -0,0 +1,3 @@
module core
go 1.22

@ -1,3 +0,0 @@
module active3
go 1.22

@ -3,7 +3,9 @@ go 1.22
use (
./A
./AATest
./core/ablds
./core/aflds
.
./core/acache
./core/fields
)
Loading…
Cancel
Save

Powered by TurnKey Linux.