restructurando el codigo para que fields se construya a partir del generico dfield

master
DEV 2 years ago
parent cedcb72337
commit 62bab50f11

@ -2,6 +2,8 @@ package main
import (
"errs"
"errs/erjson"
"errs/erstfy"
"errs/ertext"
"errs/wrap"
"fmt"
@ -56,7 +58,8 @@ func main() {
*/
//fmt.Printf("%s \n",string(errs.Encode(e,nil)))
fmt.Printf("%s \n",string(erstfy.DefaultStringer().Stringify(e)))
fmt.Printf("%s \n",string(errs.Encode(e,erjson.DefaultEncoder())))
fmt.Printf("%s \n",string(errs.Encode(l,ertext.DefaultEncoder())))

@ -22,18 +22,19 @@
// limitations under the License.
// ------------------------------------------------------------------------
package state
package bstate
var (
G = struct {
ErrStateInvalidElem ErrCode
ErrStateInvalidLevel ErrCode
ErrCircularReference ErrCode
} {
ErrStateInvalidElem : ErrCode("state-invalid-element"),
ErrStateInvalidLevel: ErrCode("state-invalid-level"),
ErrCircularReference: ErrCode("circular-reference"),
}

@ -22,7 +22,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package state
package bstate
import "blds"

@ -33,7 +33,7 @@ type (
// ValueBuilder define métodos para construir diferentes tipos de datos dentro de un valor estructurado.
ValueBuilder interface {
Buildable (value Buildable)
//Buildable (value Buildable)
Any (value any)

@ -24,6 +24,7 @@
package erinfo
import (
"blds"
"reflect"
"sync"
"time"
@ -80,7 +81,7 @@ func getTypeCollector (rtype reflect.Type) ErrorCollector {
}
func CollectErrorFields (collector Collector, err error) {
func CollectErrorFields (obuilder blds.ObjectBuilder, err error) {
if err == nil {
return
}
@ -89,8 +90,8 @@ func CollectErrorFields (collector Collector, err error) {
rt = rt.Elem()
}
if ec,is := err.(Collectable); is {
ec.Collect(collector)
if ec,is := err.(blds.FieldBuilder); is {
ec.BuildField(obuilder)
return
}
@ -98,13 +99,13 @@ func CollectErrorFields (collector Collector, err error) {
eb,_ := g.typeCollectors[rt]
g.mux.RUnlock()
if eb != nil {
eb.CollectError(collector,err)
eb.CollectError(obuilder,err)
return
}
var nc FieldCollectors
for _,f := range g.defaultCollectors {
if f.CollectField(collector,err) {
if f.CollectField(obuilder,err) {
nc = append(nc, f)
}
}
@ -119,57 +120,57 @@ func CollectErrorFields (collector Collector, err error) {
func defaultCollectors () FieldCollectors {
return []FieldCollector{
CollectFieldFnc(func (b Collector, e error ) bool {
CollectFieldFnc(func (b blds.ObjectBuilder, e error ) bool {
if ms,is := e.(interface { Message() string }); is {
b.AddFieldString(fieldNameMessage, ms.Message())
b.Field(fieldNameMessage).String(ms.Message())
return true
}
return false
}),
CollectFieldFnc(func (b Collector, e error ) bool {
CollectFieldFnc(func (b blds.ObjectBuilder, e error ) bool {
if in,is := e.(interface { Info () string }); is {
b.AddFieldString(fieldNameInfo,in.Info())
b.Field(fieldNameInfo).String(in.Info())
return true
}
return false
}),
CollectFieldFnc(func (b Collector, e error ) bool {
CollectFieldFnc(func (b blds.ObjectBuilder, e error ) bool {
if tm,is := e.(interface { Time() time.Time }); is {
b.AddFieldTime(fieldNameTime, tm.Time())
b.Field(fieldNameTime).Time(tm.Time())
return true
}
return false
}),
CollectFieldFnc(func (b Collector, e error ) bool {
CollectFieldFnc(func (b blds.ObjectBuilder, e error ) bool {
if tm,is := e.(interface { Date() time.Time }); is {
b.AddFieldTime(fieldNameDate, tm.Date())
b.Field(fieldNameDate).Time(tm.Date())
return true
}
return false
}),
CollectFieldFnc(func (b Collector, e error ) bool {
CollectFieldFnc(func (b blds.ObjectBuilder, e error ) bool {
if tm,is := e.(interface { Param() string }); is {
b.AddFieldString(fieldNameParam, tm.Param())
b.Field(fieldNameParam).String(tm.Param())
return true
}
return false
}),
CollectFieldFnc(func (b Collector, e error ) bool {
CollectFieldFnc(func (b blds.ObjectBuilder, e error ) bool {
if tm,is := e.(interface { User() string }); is {
b.AddFieldString(fieldNameUser, tm.User())
b.Field(fieldNameUser).String(tm.User())
return true
}
return false
}),
CollectFieldFnc(func (b Collector, e error ) bool {
CollectFieldFnc(func (b blds.ObjectBuilder, e error ) bool {
if tm,is := e.(interface { Source() string }); is {
b.AddFieldString(fieldNameSource, tm.Source())
b.Field(fieldNameSource).String(tm.Source())
return true
}
return false

@ -1,70 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name c.go
// ✍️ Created by DEV
// 📅 Modified 09/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 erinfo
type ErrorBuilder struct {
fields.
}
Buildable (value Buildable)
Any (value any)
Raw (value []byte)
Binary(value []byte)
String(value string)
Bool (value bool)
Int (value int )
Int8 (value int8 )
Int16 (value int16)
Int32 (value int32)
Int64 (value int64)
Uint (value uint )
Uint8 (value uint8 )
Uint16(value uint16)
Uint32(value uint32)
Uint64(value uint64)
Float32 (value float32)
Float64 (value float64)
Error (value error)
Time (value time.Time)
Duration(value time.Duration)
Reflect (value reflect.Value)
List (func (listBuilder ListBuilder ))
Map (func (mapBuilder MapBuilder ))
Object(func (objBuilder ObjectBuilder))

@ -1,31 +0,0 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File Name collectable.go
// Created by DEV
// Modified 20/04/2024
//
// 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 erinfo
type (
Collectable interface {
Collect (collector Collector)
}
)

@ -1,51 +0,0 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File Name collector.go
// Created by DEV
// Modified 20/04/2024
//
// 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 erinfo
import (
"flds"
"reflect"
"time"
)
type (
Collector interface {
AddField (field ... flds.Field)
AddFieldAny (name string, value any)
AddFieldBool (name string, value bool)
AddFieldBinary (name string, value []byte)
AddFieldString (name string, value string)
AddFieldInt (name string, value int)
AddFieldUint (name string, value uint)
AddFieldFloat (name string, value float64)
AddFieldTime (name string, value time.Time)
AddFieldDuration(name string, value time.Duration)
AddFieldError (name string, value error)
AddFieldReflect (name string, value reflect.Value)
}
)

@ -23,20 +23,22 @@
package erinfo
import "blds"
type (
ErrorCollector interface {
CollectError (collector Collector, err error)
CollectError (obuilder blds.ObjectBuilder, err error)
}
CollectErrorFnc func(collector Collector, err error)
CollectErrorFnc func(obuilder blds.ObjectBuilder, err error)
)
func (f CollectErrorFnc) CollectError (collector Collector, err error) {
f(collector,err) }
func (f CollectErrorFnc) CollectError (obuilder blds.ObjectBuilder, err error) {
f(obuilder,err) }
func NopCollectError (_ Collector, _ error) {}
func NopCollectError (_ blds.ObjectBuilder, _ error) {}

@ -29,7 +29,6 @@ import (
"flds"
"fmt"
"reflect"
"time"
)
type (
@ -41,7 +40,7 @@ type (
Types []reflect.Type
TypesStr []string
fields flds.FieldsObject
builder objectBuilder
Causes []ErrorData
Trace stack.Trace
@ -60,7 +59,7 @@ func NewErrorData(err error) *ErrorData {
func (c *ErrorData) Fields () flds.Fields {
return c.fields.List() }
return c.builder.list() }
func (c *ErrorData) Collect (addFields,addCauses,addTrace bool) *ErrorData {
@ -95,7 +94,7 @@ func (c *ErrorData) collect (addFields,addCauses,addTrace bool) *ErrorData {
// Unwrap Fields
if addFields {
CollectErrorFields(c,ne)
CollectErrorFields(&c.builder,ne)
}
// Unwrap Causes
@ -135,7 +134,7 @@ func (c *ErrorData) collect (addFields,addCauses,addTrace bool) *ErrorData {
return c
}
/*
func checkError (err error) {
if err != nil {
panic(err)
@ -187,3 +186,4 @@ func (c *ErrorData) AddFieldReflect (name string, value reflect.Value){
checkError(c.fields.Add(flds.NewFieldReflect(name,value))) }
*/

@ -23,19 +23,21 @@
package erinfo
import "blds"
type (
FieldCollector interface {
CollectField (collector Collector, err error) bool
CollectField (obuilder blds.ObjectBuilder, err error) bool
}
CollectFieldFnc func(collector Collector, err error) bool
CollectFieldFnc func(obuilder blds.ObjectBuilder, err error) bool
)
func (f CollectFieldFnc) CollectField (collector Collector, err error) bool {
return f(collector,err) }
func (f CollectFieldFnc) CollectField (obuilder blds.ObjectBuilder, err error) bool {
return f(obuilder,err) }

@ -23,6 +23,8 @@
package erinfo
import "blds"
type (
FieldCollectors []FieldCollector
@ -33,17 +35,17 @@ type (
func (c FieldCollectors) CollectError (collector Collector, err error) {
func (c FieldCollectors) CollectError (obuilder blds.ObjectBuilder, err error) {
for _,f := range c {
f.CollectField(collector,err)
f.CollectField(obuilder,err)
}
}
func (c FieldCollectors) CollectField (collector Collector, err error) bool {
func (c FieldCollectors) CollectField (obuilder blds.ObjectBuilder, err error) bool {
r := true
for _,fc := range c {
r = r && fc.CollectField(collector,err)
r = r && fc.CollectField(obuilder,err)
}
return r
}

@ -0,0 +1,101 @@
// ------------------------------------------------------------------------
// 🚀 Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name c.go
// ✍️ Created by DEV
// 📅 Modified 09/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 erinfo
import (
"blds"
"blds/bstate"
"flds"
"reflect"
"time"
)
type objectBuilder struct {
curName string
nexVal bool
fields flds.FieldsObject
}
func (b *objectBuilder) Field (name string) blds.ValueBuilder {
if b.nexVal {
panic(bstate.G.ErrStateInvalidElem)
}
b.curName= name
b.nexVal = true
return b
}
func (b *objectBuilder) list() flds.Fields {
return b.fields.List() }
func (b *objectBuilder) add (field flds.Field) {
if field != nil {
if er := b.fields.Add(field); er != nil {
panic(er)
}
}
b.curName= ""
b.nexVal = false
}
func (b *objectBuilder) Any (value any) { b.add (flds.NewFieldAny (b.curName,value)) }
func (b *objectBuilder) Raw (value []byte) { b.add (flds.NewFieldBinary (b.curName,value)) }
func (b *objectBuilder) Binary(value []byte) { b.add (flds.NewFieldBinary (b.curName,value)) }
func (b *objectBuilder) String(value string) { b.add (flds.NewFieldString (b.curName,value)) }
func (b *objectBuilder) Bool (value bool) { b.add (flds.NewFieldBool (b.curName,value)) }
func (b *objectBuilder) Int (value int ) { b.add (flds.NewFieldInt (b.curName,value)) }
func (b *objectBuilder) Int8 (value int8 ) { b.add (flds.NewFieldInt (b.curName,int(value))) }
func (b *objectBuilder) Int16 (value int16) { b.add (flds.NewFieldInt (b.curName,int(value))) }
func (b *objectBuilder) Int32 (value int32) { b.add (flds.NewFieldInt (b.curName,int(value))) }
func (b *objectBuilder) Int64 (value int64) { b.add (flds.NewFieldInt (b.curName,int(value))) }
func (b *objectBuilder) Uint (value uint ) { b.add (flds.NewFieldUint (b.curName,value)) }
func (b *objectBuilder) Uint8 (value uint8 ) { b.add (flds.NewFieldUint (b.curName,uint(value))) }
func (b *objectBuilder) Uint16(value uint16) { b.add (flds.NewFieldUint (b.curName,uint(value))) }
func (b *objectBuilder) Uint32(value uint32) { b.add (flds.NewFieldUint (b.curName,uint(value))) }
func (b *objectBuilder) Uint64(value uint64) { b.add (flds.NewFieldUint (b.curName,uint(value))) }
func (b *objectBuilder) Float32 (value float32) { b.add (flds.NewFieldFloat (b.curName,float64(value))) }
func (b *objectBuilder) Float64 (value float64) { b.add (flds.NewFieldFloat (b.curName,value)) }
func (b *objectBuilder) Error (value error) { b.add (flds.NewFieldError (b.curName,value)) }
func (b *objectBuilder) Time (value time.Time) { b.add (flds.NewFieldTime (b.curName,value)) }
func (b *objectBuilder) Duration(value time.Duration) { b.add (flds.NewFieldDuration (b.curName,value)) }
func (b *objectBuilder) Reflect (value reflect.Value) { b.add (flds.NewFieldReflect (b.curName,value)) }
func (b *objectBuilder) List (_ func (_ blds.ListBuilder )) { b.add(nil) }
func (b *objectBuilder) Map (_ func (_ blds.MapBuilder )) { b.add(nil) }
func (b *objectBuilder) Object(_ func (_ blds.ObjectBuilder)) { b.add(nil) }

@ -302,7 +302,7 @@ func (b *jsonBuilder) writeField (name, value, indent string, quote, coma, nl bo
func (b *jsonBuilder) writeFieldValue (field flds.Field, level int) bool {
switch field.Kind() {
case flds.KindFloat:
v,_ := field.AsFloat()
v := field.ValueFloat()
if v == 0 && b.f.HasIgnoreDefaults() {
return false
}
@ -310,7 +310,7 @@ func (b *jsonBuilder) writeFieldValue (field flds.Field, level int) bool {
return true
case flds.KindInt:
v,_ := field.AsInt()
v := field.ValueInt()
if v == 0 && b.f.HasIgnoreDefaults() {
return false
}
@ -318,7 +318,7 @@ func (b *jsonBuilder) writeFieldValue (field flds.Field, level int) bool {
return true
case flds.KindString:
v,_ := field.AsString()
v := field.ValueString()
if len(v) == 0 && b.f.HasIgnoreDefaults() {
return false
}
@ -326,7 +326,7 @@ func (b *jsonBuilder) writeFieldValue (field flds.Field, level int) bool {
return true
case flds.KindTime:
v,_ := field.AsTime()
v := field.ValueTime()
if v.IsZero() && b.f.HasIgnoreDefaults(){
return false
}
@ -334,7 +334,7 @@ func (b *jsonBuilder) writeFieldValue (field flds.Field, level int) bool {
return true
case flds.KindDuration:
v,_ := field.AsDuration()
v := field.ValueDuration()
if v == 0 && b.f.HasIgnoreDefaults(){
return false
}
@ -342,7 +342,7 @@ func (b *jsonBuilder) writeFieldValue (field flds.Field, level int) bool {
return true
case flds.KindBool:
v,_ := field.AsBool()
v := field.ValueBool()
if !v && b.f.HasIgnoreDefaults() {
return false
}
@ -350,7 +350,7 @@ func (b *jsonBuilder) writeFieldValue (field flds.Field, level int) bool {
return true
case flds.KindBinary:
v,_ := field.AsBinary()
v := field.ValueBinary()
if v == nil && b.f.HasIgnoreDefaults() {
return false
}

@ -24,7 +24,7 @@
package errs
import (
"errs/erinfo"
"blds"
"errs/erstfy"
"fmt"
)
@ -80,7 +80,7 @@ func (e ErrParam) Stringify (_ bool) string {
erstfy.DefaultStringer().LabelLine("message", e.message))
}
func (e ErrParam) Collect (c erinfo.Collector) {
c.AddFieldString("message",e.message)
c.AddFieldString("param",e.param)
func (e ErrParam) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field("message").String(e.message)
obuilder.Field("param").String(e.param)
}

@ -232,7 +232,7 @@ func (b *TextBuilder) writeField (field flds.Field, indent string) {
b.writeFieldBegin(field.Name(),indent)
if !field.Kind().IsAny() {
b.b.AppendWith(bfrs.AppendFnc(field.AppendAsString))
b.b.AppendWith(field)
b.writeFieldEnd()
return
}

@ -25,7 +25,7 @@
package wrap
import (
"errs/erinfo"
"blds"
"errs/erstfy"
"flds"
)
@ -60,7 +60,7 @@ func (e Field) String () string {
func (e Field) Stringify (partial bool) string {
ln := erstfy.DefaultStringer().LabelLine(e.Name(),string(e.AppendAsString(nil)))
ln := erstfy.DefaultStringer().LabelLine(e.Name(),string(e.Append(nil)))
if partial {
return ln
}
@ -68,5 +68,5 @@ func (e Field) Stringify (partial bool) string {
func (e Field) Collect (collector erinfo.Collector) {
collector.AddField(e.Field) }
func (e Field) BuildField (obuilder blds.ObjectBuilder) {
e.Field.BuildField(obuilder) }

@ -25,7 +25,7 @@ package wrap
import (
"bfrs"
"errs/erinfo"
"blds"
"errs/erstfy"
"flds"
)
@ -71,7 +71,7 @@ func (e Fields) Stringify (partial bool) string {
defer bfrs.ReleaseABuffer(b)
sy := erstfy.DefaultStringer()
for _,f := range e.FieldsObject.List() {
_,_ = b.Write(sy.LabelAppenderLine(f.Name(),f.AppendAsString))
_,_ = b.Write(sy.LabelAppenderLine(f.Name(),f.Append))
}
ln = b.String()
bfrs.ReleaseABuffer(b)
@ -84,5 +84,5 @@ func (e Fields) Stringify (partial bool) string {
func (e Fields) Collect (c erinfo.Collector) {
c.AddField(e.List()...) }
func (e Fields) BuildField (obuilder blds.ObjectBuilder) {
e.BuildField(obuilder) }

@ -26,7 +26,6 @@ package wrap
import (
"bfrs"
"blds"
"errs/erinfo"
"errs/erstfy"
"time"
)
@ -87,16 +86,6 @@ func (e Info) Stringify (partial bool) string {
return erstfy.DefaultStringer().Stringify(e.error,ln)
}
func (e Info) Collect (c erinfo.Collector) {
if len(e.Message) > 0 { c.AddFieldString("message", e.Message) }
if len(e.Info) > 0 { c.AddFieldString("info", e.Info) }
if len(e.Desc) > 0 { c.AddFieldString("desc", e.Desc) }
if len(e.Link) > 0 { c.AddFieldString("link",e.Link) }
if len(e.Help) > 0 { c.AddFieldString("help",e.Help) }
c.AddFieldTime("date",e.Date)
}
func (e Info) Build (builder blds.Builder) {
builder.Object(
@ -106,7 +95,6 @@ func (e Info) Build (builder blds.Builder) {
})
}
func (e Info) BuildField (builder blds.ObjectBuilder) {
builder.Field("message").String(e.Message)
builder.Field("info").String(e.Info)

@ -24,7 +24,7 @@
package wrap
import (
"errs/erinfo"
"blds"
"errs/erstfy"
"fmt"
)
@ -72,5 +72,5 @@ func (e Message) Stringify (partial bool) string {
}
func (e Message) Collect (c erinfo.Collector) {
c.AddFieldString("message",e.message) }
func (e Message) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field("message").String(e.message) }

@ -28,6 +28,11 @@ import (
"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.
@ -266,3 +271,137 @@ func TypeToKind(value any) Kind {
return KindAny
}
}
func NewFieldAny (name string, value any) *GField[any] {
return NewGField[any](name,KindAny,value) }
func NewDFieldAny (name string, valueFn func() any) *GField[any] {
return NewGDField[any](name,KindAny,valueFn) }
func NewDOFieldAny(name string, valueFn func()any) *GField[any] {
return NewGDOField[any](name,KindAny,valueFn) }
func NewFieldBool (name string, value bool) *GField[bool] {
return NewGField[bool](name,KindBool,value) }
func NewDFieldBool (name string, valueFn func() bool) *GField[bool] {
return NewGDField[bool](name,KindBool,valueFn) }
func NewDOFieldBool(name string, valueFn func()bool) *GField[bool] {
return NewGDOField[bool](name,KindBool,valueFn) }
func NewFieldBinary (name string, value []byte) *GField[[]byte] {
return NewGField[[]byte](name,KindBinary,value) }
func NewDFieldBinary (name string, valueFn func() []byte) *GField[[]byte] {
return NewGDField[[]byte](name,KindBinary,valueFn) }
func NewDOFieldBinary(name string, valueFn func()[]byte) *GField[[]byte] {
return NewGDOField[[]byte](name,KindBinary,valueFn) }
func NewFieldString (name string, value string) *GField[string] {
return NewGField[string](name,KindString,value) }
func NewDFieldString (name string, valueFn func() string) *GField[string] {
return NewGDField[string](name,KindString,valueFn) }
func NewDOFieldString(name string, valueFn func()string) *GField[string] {
return NewGDOField[string](name,KindString,valueFn) }
func NewFieldInt (name string, value int) *GField[int] {
return NewGField[int](name,KindInt,value) }
func NewDFieldInt (name string, valueFn func() int) *GField[int] {
return NewGDField[int](name,KindInt,valueFn) }
func NewDOFieldInt(name string, valueFn func()int) *GField[int] {
return NewGDOField[int](name,KindInt,valueFn) }
func NewFieldUint (name string, value uint) *GField[uint] {
return NewGField[uint](name,KindUint,value) }
func NewDFieldUint (name string, valueFn func() uint) *GField[uint] {
return NewGDField[uint](name,KindUint,valueFn) }
func NewDOFieldUint(name string, valueFn func()uint) *GField[uint] {
return NewGDOField[uint](name,KindUint,valueFn) }
func NewFieldFloat (name string, value float64) *GField[float64] {
return NewGField[float64](name,KindFloat,value) }
func NewDFieldFloat (name string, valueFn func() float64) *GField[float64] {
return NewGDField[float64](name,KindFloat,valueFn) }
func NewDOFieldFloat(name string, valueFn func()float64) *GField[float64] {
return NewGDOField[float64](name,KindFloat,valueFn) }
func NewFieldTime (name string, value time.Time) *GField[time.Time] {
return NewGField[time.Time](name,KindTime,value) }
func NewDFieldTime (name string, valueFn func() time.Time) *GField[time.Time] {
return NewGDField[time.Time](name,KindTime,valueFn) }
func NewDOFieldTime(name string, valueFn func()time.Time) *GField[time.Time] {
return NewGDOField[time.Time](name,KindTime,valueFn) }
func NewFieldDuration (name string, value time.Duration) *GField[time.Duration] {
return NewGField[time.Duration](name,KindDuration,value) }
func NewDFieldDuration (name string, valueFn func() time.Duration) *GField[time.Duration] {
return NewGDField[time.Duration](name,KindDuration,valueFn) }
func NewDOFieldDuration(name string, valueFn func()time.Duration) *GField[time.Duration] {
return NewGDOField[time.Duration](name,KindDuration,valueFn) }
func NewFieldReflect (name string, value reflect.Value) *GField[reflect.Value] {
return NewGField[reflect.Value](name,KindReflect,value) }
func NewDFieldReflect (name string, valueFn func() reflect.Value) *GField[reflect.Value] {
return NewGDField[reflect.Value](name,KindReflect,valueFn) }
func NewDOFieldReflect(name string, valueFn func()reflect.Value) *GField[reflect.Value] {
return NewGDOField[reflect.Value](name,KindReflect,valueFn) }
func NewFieldError (name string, value error) *GField[error] {
return NewGField[error](name,KindError,value) }
func NewDFieldError (name string, valueFn func() error) *GField[error] {
return NewGDField[error](name,KindError,valueFn) }
func NewDOFieldError(name string, valueFn func()error) *GField[error] {
return NewGDOField[error](name,KindError,valueFn) }

@ -23,55 +23,38 @@
package flds
import (
"bfrs"
"blds"
"reflect"
"time"
)
type (
Field interface {
bfrs.Appender
blds.FieldBuilder
Kind () Kind
Name () string
Value() any
}
)
ValueBool () bool
ValueBinary () []byte
ValueString () string
ValueInt () int
ValueUint () uint
ValueFloat () float64
ValueTime () time.Time
ValueDuration() time.Duration
ValueReflect () reflect.Value
ValueError () error
/*🚫 DEPRECATED
func FieldAsBuildable (field Field) blds.BuildFnc {
return func (b blds.Builder) {
buildFieldAsObject(field,b)
}
}
func buildFieldAsObject (field Field, builder blds.Builder) {
builder.Object(func(ob blds.ObjectBuilder){
buildFieldAsField(field,ob)
})
}
func buildFieldAsField (field Field, obuilder blds.ObjectBuilder) {
vb := obuilder.Field(field.Name())
switch field.Kind() {
case KindAny : vb.Any (field.Value())
case KindBool : v,_ := field.AsBool(); vb.Bool(v)
case KindBinary : v,_ := field.AsBinary(); vb.Binary(v)
case KindString : v,_ := field.AsString(); vb.String(v)
case KindInt : v,_ := field.AsInt(); vb.Int(v)
case KindUint : v,_ := field.AsUint(); vb.Uint(v)
case KindFloat : v,_ := field.AsFloat(); vb.Float64(v)
case KindTime : v,_ := field.AsTime(); vb.Time(v)
case KindDuration: v,_ := field.AsDuration(); vb.Duration(v)
case KindError : v,_ := field.AsError(); vb.Error(v)
case KindReflect : v,_ := field.AsReflect(); vb.Reflect(v)
default:
vb.Any(field.Value())
}
}
*/
)

@ -1,142 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
"reflect"
"time"
)
type (
FieldAny struct {
partialField[any]
}
)
func NewFieldAny (name string, value any) *FieldAny {
return &FieldAny{ partialField : makePartialFieldLocal[any](name,value) } }
func NewDFieldAny(name string, valueFn func() any) *FieldAny {
return &FieldAny{ partialField : makePartialFieldDefer[any](name,valueFn) } }
func NewDOFieldAny (name string, valueFn func()any) *FieldAny {
return &FieldAny{ partialField : makePartialFieldOnce[any](name,valueFn) }}
func (f FieldAny) Kind() Kind {
return KindAny | f.valuerKind() }
func (f FieldAny) AsBool() (bool,bool) {
v,ok := f.Native().(bool)
return v,ok
}
func (f FieldAny) AsBinary() ([]byte,bool) {
v, ok := f.Native().([]byte)
return v, ok
}
func (f FieldAny) AsString() (string,bool) {
v,ok := f.Native().(string)
return v,ok
}
func (f FieldAny) AsInt() (int,bool) {
switch t := f.Native().(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) AsUint() (uint,bool) {
switch t := f.Native().(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) AsFloat() (float64,bool) {
vl := f.Native()
v, ok := vl.(float64)
if !ok {
var f32 float32
if f32,ok = vl.(float32); ok {
v = float64(f32)
}
}
return v, ok
}
func (f FieldAny) Date () (time.Time,bool) {
v, ok := f.Native().(time.Time)
return v, ok
}
func (f FieldAny) AsTime() (time.Time,bool) {
v, ok := f.Native().(time.Time)
return v, ok
}
func (f FieldAny) AsDuration() (time.Duration,bool) {
v, ok := f.Native().(time.Duration)
return v, ok
}
func (f FieldAny) AsError() (error,bool) {
v, ok := f.Native().(error)
return v, ok
}
func (f FieldAny) AsReflect() (reflect.Value,bool) {
v, ok := f.Native().(reflect.Value)
return v, ok
}
func (f FieldAny) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){ f.BuildField(b) }) }
func (f FieldAny) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).Any(f.Native()) }

@ -1,65 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
"encoding/base64"
)
type (
FieldBinary struct {
partialField[[]byte]
}
)
func NewFieldBinary (name string, value []byte) *FieldBinary {
return &FieldBinary{ partialField : makePartialFieldLocal[[]byte](name,value) } }
func NewDFieldBinary (name string, valueFn func() []byte) *FieldBinary {
return &FieldBinary{ partialField : makePartialFieldDefer[[]byte](name,valueFn) } }
func NewDOFieldBinary (name string, valueFn func() []byte) *FieldBinary {
return &FieldBinary{ partialField : makePartialFieldOnce[[]byte](name,valueFn) } }
func (f FieldBinary) Kind () Kind {
return KindBinary | f.valuerKind() }
func (f FieldBinary) AsBinary() ([]byte,bool) {
return f.Native(),true }
func (f FieldBinary) AppendAsString (dest []byte) []byte {
return append(dest,[]byte(base64.StdEncoding.EncodeToString(f.Native()))...) }
func (f FieldBinary) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){ f.BuildField(b) }) }
func (f FieldBinary) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).Binary(f.Native()) }

@ -1,67 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
"strconv"
)
type (
FieldBool struct {
partialField[bool]
}
)
func NewFieldBool (name string, value bool) *FieldBool {
return &FieldBool{ partialField: makePartialFieldLocal[bool](name,value) } }
func NewDFieldBool (name string, valueFn func() bool) *FieldBool {
return &FieldBool{ partialField: makePartialFieldDefer[bool](name,valueFn) } }
func NewDOFieldBool (name string, valueFn func() bool) *FieldBool {
return &FieldBool{ partialField: makePartialFieldOnce[bool](name,valueFn) } }
func (f FieldBool) Kind () Kind {
return KindBool | f.valuerKind() }
func (f FieldBool) AsBool() (bool,bool) {
return f.Native(),true }
func (f FieldBool) AppendAsString (dest []byte) []byte {
return strconv.AppendBool(dest,f.Native()) }
func (f FieldBool) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){ f.BuildField(b) }) }
func (f FieldBool) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).Bool(f.Native()) }

@ -1,66 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
"strconv"
"time"
)
type (
FieldDuration struct {
partialField [time.Duration]
}
)
func NewFieldDuration (name string, value time.Duration) *FieldDuration {
return &FieldDuration{ partialField : makePartialFieldLocal[time.Duration](name,value) } }
func NewDFieldDuration (name string, valueFn func() time.Duration) *FieldDuration {
return &FieldDuration{ partialField : makePartialFieldDefer[time.Duration](name,valueFn) } }
func NewDOFieldDuration (name string, valueFn func() time.Duration) *FieldDuration {
return &FieldDuration{ partialField : makePartialFieldOnce[time.Duration](name,valueFn) } }
func (f FieldDuration) Kind () Kind {
return KindDuration | f.valuerKind() }
func (f FieldDuration) AsDuration() (time.Duration,bool) {
return f.Native(),true }
func (f FieldDuration) AppendAsString(dest []byte) []byte {
return strconv.AppendUint(dest,uint64(f.Native()),10) }
func (f FieldDuration) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){ f.BuildField(b) })}
func (f FieldDuration) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).Duration(f.Native()) }

@ -1,74 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
"typs/strs"
)
type (
FieldError struct {
partialField[error]
}
)
func NewFieldError (name string, value error) *FieldError {
return &FieldError{ partialField : makePartialFieldLocal[error](name,value) }}
func NewDFieldError (name string, valueFn func() error) *FieldError {
return &FieldError{ partialField : makePartialFieldDefer[error](name,valueFn) } }
func NewDOFieldError (name string, valueFn func() error) *FieldError {
return &FieldError{ partialField : makePartialFieldOnce[error](name,valueFn) } }
func (f FieldError) Kind () Kind {
return KindError | f.valuerKind() }
func (f FieldError) AsError() (error,bool) {
return f.Native(),true }
func (f FieldError) AppendAsString (dest []byte) []byte {
e := f.Native()
if e == nil {
return dest
}
if st,is := e.(strs.Stringer); is {
return append(dest,[]byte(st.String())...)
}
return append(dest,[]byte(e.Error())...)
}
func (f FieldError) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){ f.BuildField(b) }) }
func (f FieldError) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).Error(f.Native()) }

@ -1,66 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
"strconv"
)
type (
FieldFloat struct {
partialField[float64]
}
)
func NewFieldFloat (name string, value float64) *FieldFloat {
return &FieldFloat{ partialField : makePartialFieldLocal[float64](name,value) } }
func NewDFieldFloat (name string, valueFn func()float64) *FieldFloat {
return &FieldFloat{ partialField : makePartialFieldDefer[float64](name,valueFn) } }
func NewDOFieldFloat (name string, valueFn func()float64) *FieldFloat {
return &FieldFloat{ partialField : makePartialFieldOnce[float64](name,valueFn) } }
func (f FieldFloat) Kind () Kind {
return KindFloat | f.valuerKind() }
func (f FieldFloat) AsFloat() (float64,bool) {
return f.Native(),true }
func (f FieldFloat) AppendAsString (dest []byte) []byte {
return strconv.AppendFloat(dest,f.Native(),'f',-1,64) }
func (f FieldFloat) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){ f.BuildField(b) }) }
func (f FieldFloat) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).Float64(f.Native()) }

@ -1,71 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
"strconv"
)
type (
FieldInt struct {
partialField[int]
}
)
func NewFieldInt (name string, value int) *FieldInt {
return &FieldInt{ partialField : makePartialFieldLocal[int](name,value) }}
func NewDFieldInt (name string, valueFn func()int) *FieldInt {
return &FieldInt{ partialField : makePartialFieldDefer[int](name,valueFn) }}
func NewDOFieldInt (name string, valueFn func()int) *FieldInt {
return &FieldInt{ partialField : makePartialFieldOnce[int](name,valueFn) }}
func (f FieldInt) Kind () Kind {
return KindInt | f.valuerKind() }
func (f FieldInt) AsInt() (int,bool) {
return f.Native(),true }
func (f FieldInt) AppendAsString (dest []byte) []byte {
return strconv.AppendInt(dest,int64(f.Native()),10) }
func (f FieldInt) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){ f.BuildField(b) }) }
func (f FieldInt) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).Int(f.Native()) }

@ -1,69 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
"fmt"
"reflect"
)
type (
FieldReflect struct {
partialField[reflect.Value]
}
)
func NewFieldReflect (name string, value reflect.Value) *FieldReflect {
return &FieldReflect{ partialField : makePartialFieldLocal[reflect.Value](name,value) } }
func NewDFieldReflect (name string, valueFn func()reflect.Value) *FieldReflect {
return &FieldReflect{ partialField : makePartialFieldDefer[reflect.Value](name,valueFn) } }
func NewDOFieldReflect (name string, valueFn func()reflect.Value) *FieldReflect {
return &FieldReflect{ partialField : makePartialFieldOnce[reflect.Value](name,valueFn) } }
func (f FieldReflect) Kind () Kind {
return KindReflect | f.valuerKind() }
func (f FieldReflect) AsReflect() (reflect.Value,bool) {
return f.Native(),true }
func (f FieldReflect) AppendAsString (dest []byte) []byte {
return append (dest,fmt.Sprintf("%#v",f.Native())...) }
func (f FieldReflect) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){ f.BuildField(b) }) }
func (f FieldReflect) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).Reflect(f.Native()) }

@ -1,63 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
)
type (
FieldString struct {
partialField[string]
}
)
func NewFieldString (name string, value string) *FieldString {
return &FieldString{ partialField : makePartialFieldLocal[string](name,value) } }
func NewDFieldString (name string, valueFn func() string) *FieldString {
return &FieldString{ partialField : makePartialFieldDefer[string](name,valueFn) } }
func NewDOFieldString (name string, valueFn func() string) *FieldString {
return &FieldString{ partialField : makePartialFieldOnce[string](name,valueFn) } }
func (f FieldString) Kind () Kind {
return KindString | f.valuerKind() }
func (f FieldString) AsString() (string,bool) {
return f.Native(),true }
func (f FieldString) AppendAsString (dest []byte) []byte {
return append (dest,[]byte(f.Native())...)}
func (f FieldString) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){ f.BuildField(b) }) }
func (f FieldString) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).String(f.Native()) }

@ -1,65 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
"time"
)
type (
FieldTime struct {
partialField[time.Time]
}
)
func NewFieldTime (name string, value time.Time) *FieldTime {
return &FieldTime{ partialField : makePartialFieldLocal[time.Time](name,value) } }
func NewDFieldTime (name string, valueFn func() time.Time) *FieldTime {
return &FieldTime{ partialField : makePartialFieldDefer[time.Time](name,valueFn) } }
func NewDOFieldTime (name string, valueFn func() time.Time) *FieldTime {
return &FieldTime{ partialField : makePartialFieldOnce[time.Time](name,valueFn) } }
func (f FieldTime) Kind () Kind {
return KindTime | f.valuerKind() }
func (f FieldTime) AsTime() (time.Time,bool) {
return f.Native(),true }
func (f FieldTime) AppendAsString (dest []byte) []byte {
return append (dest,[]byte(f.Native().String())...)}
func (f FieldTime) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){ f.BuildField(b) }) }
func (f FieldTime) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).Time(f.Native()) }

@ -1,69 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"blds"
"strconv"
)
type (
FieldUint struct {
partialField[uint]
}
)
func NewFieldUint (name string, value uint) *FieldUint {
return &FieldUint{ partialField : makePartialFieldLocal[uint](name,value) }}
func NewDFieldUint (name string, valueFn func() uint) *FieldUint {
return &FieldUint{ partialField : makePartialFieldDefer[uint](name,valueFn) }}
func NewDOFieldUint (name string, valueFn func() uint) *FieldUint {
return &FieldUint{ partialField : makePartialFieldOnce[uint](name,valueFn) }}
func (f FieldUint) Kind () Kind {
return KindUint | f.valuerKind() }
func (f FieldUint) AsUint() (uint,bool) {
return f.Native(),true }
func (f FieldUint) AppendAsString (dest []byte) []byte {
return strconv.AppendUint (dest,uint64(f.Native()),10) }
func (f FieldUint) Build (builder blds.Builder) {
builder.Object(func(b blds.ObjectBuilder){
b.Field(f.name).Uint(f.Native()) }) }
func (f FieldUint) BuildField (obuilder blds.ObjectBuilder) {
obuilder.Field(f.name).Uint(f.Native()) }

@ -6,7 +6,7 @@
// ✍️ Created by DEV
// 📅 Modified 01/05/2024
//
// 🔒 COPYRIGHT Copyright 2024 activething.com
// 🔒 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.
@ -143,7 +143,11 @@ func (f Fields) indexOf(name string) int {
func (f Fields) Build (builder blds.Builder) {
builder.List(func(lb blds.ListBuilder) {
for _,fl := range f {
buildFieldAsObject(fl,lb.Item())
lb.Item().Object(func(ob blds.ObjectBuilder){
fl.BuildField(ob)
})
}
})
}

@ -196,7 +196,7 @@ func (f *FieldsObject) Sort() {
func (f *FieldsObject) Build (builder blds.Builder) {
builder.Object(func(ob blds.ObjectBuilder) {
for _,fl := range f.fields {
buildFieldAsField(fl,ob)
fl.BuildField(ob)
}
})
}

@ -1,80 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"reflect"
"time"
)
type (
// partialField representa un Field parcialmente definido con solo el nombre.
// Implementa el interface typeResolver 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[T any] struct {
valuer[T]
name string
}
)
func makePartialFieldLocal[T any] (name string, value T) partialField[T]{
return partialField[T]{
name : name,
valuer: makeValueValuer[T](value) }}
func makePartialFieldDefer[T any] (name string, valueFn func() T) partialField[T] {
return partialField[T]{
name : name,
valuer: makeDeferValuer[T](valueFn) }}
func makePartialFieldOnce [T any] (name string, valueFn func() T) partialField[T] {
return partialField[T]{
name : name,
valuer: newOnceValuer[T](valueFn) }}
func (f partialField[T]) Name() string {
return f.name }
func (f partialField[T]) AsBool() (bool, bool) { return false, false }
func (f partialField[T]) AsString() (string, bool) { return "", false }
func (_ partialField[T]) AsBinary() ([]byte, bool) { return nil, false }
func (_ partialField[T]) AsInt() (int, bool) { return 0, false }
func (_ partialField[T]) AsUint() (uint, bool) { return 0, false }
func (_ partialField[T]) AsFloat() (float64, bool) { return 0, false }
func (_ partialField[T]) AsTime() (time.Time, bool){ return g.timeZero, false }
func (_ partialField[T]) AsDuration() (time.Duration, bool){ return 0, false }
func (_ partialField[T]) AsError() (error, bool) { return nil, false }
func (_ partialField[T]) AsReflect() (reflect.Value, bool) { return g.reflectZero, false }

@ -1,36 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name string_appender.go
// ✍️ Created by DEV
// 📅 Modified 06/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 flds
type (
StringAppender interface {
AppendAsString (dest []byte) []byte
}
)

@ -1,81 +0,0 @@
// ------------------------------------------------------------------------
// 🚀 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 flds
import (
"reflect"
"time"
)
type (
// typeResolver 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.
typeResolver interface {
// AsBool intenta resolver y devolver el valor como un booleano.
// Retorna el valor booleano y un indicador de éxito.
AsBool() (bool, bool)
// AsBinary intenta resolver y devolver el valor como un slice de bytes.
// Retorna el slice de bytes y un indicador de éxito.
AsBinary() ([]byte, bool)
// AsString intenta resolver y devolver el valor como una cadena de texto.
// Retorna la cadena de texto y un indicador de éxito.
AsString() (string, bool)
// AsInt intenta resolver y devolver el valor como un entero.
// Retorna el entero y un indicador de éxito.
AsInt() (int, bool)
// AsUint intenta resolver y devolver el valor como un entero sin signo.
// Retorna el entero sin signo y un indicador de éxito.
AsUint() (uint, bool)
// AsFloat 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.
AsFloat() (float64, bool)
// AsTime intenta resolver y devolver el valor como una marca de tiempo.
// Retorna la marca de tiempo y un indicador de éxito.
AsTime() (time.Time, bool)
// AsDuration intenta resolver y devolver el valor como una duración de tiempo
// Retorna la duración y un indicador de éxito.
AsDuration() (time.Duration, bool)
// AsError intenta resolver y devolver el valor como un error.
// Retorna el error y un indicador de éxito.
AsError() (error, bool)
// AsReflect intenta resolver y devolver el valor como un reflect.Value.
// Retorna el reflect.Value y un indicador de éxito.
AsReflect() (reflect.Value, bool)
}
)
Loading…
Cancel
Save

Powered by TurnKey Linux.