corregidos los errores de la descomposicion del git

rev-packs
DEV 2 years ago
parent cea56aba14
commit 6aec02d432

@ -30,6 +30,7 @@ import (
"strings"
"sync"
"syncs/queue"
"vals/flds"
)
type (
@ -363,7 +364,7 @@ func (l *ActiveLogger) handleLoggers(entry *Entry, doFn func(c Logger, e *Entry)
if l.logErrors {
en = AcquireEntry(l,LevelError,ms,ne,
EntryWithExclude (nm),
EntryWithField (entryFieldLogger,nm,true))
EntryWithFields (flds.NewAFieldString(entryFieldLogger,nm)))
}
l.handleError(ne,en,co)
}

@ -27,6 +27,8 @@ import (
"apacks"
"atypes/slices"
"time"
"vals/flds"
"vals/flds/pkflds"
)
type (
@ -45,6 +47,7 @@ type (
Error error
Data any
Fields flds.AFields
Excludes slices.Strings
}
@ -102,26 +105,11 @@ func (e *Entry) reset () *Entry {
func (e *Entry) Clone() *Entry {
n := *e
/*
l:=len(e.Fields)
if l > 0 {
n.Fields = make(vals.Fields,len(e.Fields))
for i:=0; i<l; i++ {
n.Fields[i]=e.Fields[i]
}
}
*/
return &n
}
func (e *Entry) BuildPack(packer apacks.ValuePacker) error {
packer.PackObject(func (b apacks.ObjectPackBuilder, _ apacks.Flags){
b.FieldUInt64("id",e.Id,0)
b.FieldDate("date",e.Date,0)
pkflds.AddAFieldsToPack(b,e.Fields)
},0)
return nil
@ -151,9 +139,16 @@ func EntryWithExtender(extender EntryExtender) EntryFnc {
extender.ExtendEntry(e) } }
func EntryWithField (name string, value any, overwrite bool) EntryFnc {
return func(e *Entry) {
func EntryWithField (name string, value any) EntryFnc {
return func (e *Entry) {
e.Fields = e.Fields.SetField(flds.NewAField(name,value)) }
}
func EntryWithFields (field ...flds.AField) EntryFnc {
return func(e *Entry) {
for _,f := range field {
e.Fields = e.Fields.SetField(f)
}
}
}

@ -31,6 +31,8 @@ import (
"errs"
"reflect"
"time"
"vals/flds"
"vals/flds/pkflds"
)
@ -112,6 +114,9 @@ func (p *JSONPacker) PackAny (value any, flags apacks.Flags) {
p.state.W(d)
}
case flds.AFields:
p.state.SetError(pkflds.AFieldsListPacker(v).BuildPack(p))
case bool : packBool (p,v,flags )
case string : packString(p,v,flags )

@ -25,6 +25,7 @@ package pkjson
import (
"apacks"
"fmt"
"reflect"
"sync"
)
@ -68,8 +69,9 @@ func rTypePacker (rtype reflect.Type) rPackerFnc {
func _rTypePacker(rtype reflect.Type) rPackerFnc {
fmt.Printf(" %s Implementa %s ) %v\n",rtype.String(),g.packBuilderType.String(),rtype.Implements(g.packBuilderType))
if rtype.Implements(g.packBuilderType) {
fmt.Println("LLeve hasta la reflection")
return func (p *JSONPacker, v reflect.Value, f apacks.Flags) {
p.state.SetError(v.Interface().(apacks.PackBuilder).BuildPack(p))
}

@ -59,64 +59,23 @@ func Append2 (_ *alogs.Entry) error {
func main() {
var f flds.AFields
f = f.AddField(flds.NewAFieldString("un","dato"))
f = f.AddField(flds.NewAFieldSigned("dos",2))
p := pkjson.Pack(f)
if !p.Ok() {
fmt.Print(errs.Encode(p.Fail(),nil))
return
}
fmt.Print(string(p.Value()))
/*
cx,cl := context.WithCancel(context.Background())
//cl()
l,er := alogs.NewActiveLogger(alogs.LevelAll,
alogs.ActiveLoggerWithContext(cx,true),
alogs.ActiveLoggerWithOnError(func(a *alogs.ActiveLogger,err error, s alogs.Logger){
if s != nil {
//fmt.Printf("Error producido en logger [%s] se procede a su paro\n", s.Name())
//fmt.Println(errs.Encode(err,nil))
fmt.Print(errs.Encode(s.Stop(),nil))
}
}),
entry := alogs.NewEntry(nil,alogs.LevelFatal|alogs.LevelDebug,"Un mensage",nil,
alogs.EntryWithFields(
flds.NewAFieldString("UnCampo","valor"),
flds.NewAFieldSigned("UnNumero",3),
flds.NewAFieldSigned("UnNumero",1)),
alogs.EntryWithField("Una cabncion",true),
)
if er != nil {
fmt.Print(errs.Encode(er,nil))
time.Sleep(500*time.Millisecond)
return
}
l1,_:= alogs.NewLoggerCore("MiLogger",alogs.LevelAll,alogs.LoggerCoreWithAppender(alogs.AppendEntryFnc(Append)))
l2,_:=alogs.NewLoggerCore("LoggerProblematico",alogs.LevelAll,alogs.LoggerCoreWithAppender(alogs.AppendEntryFnc(Append2)))
l.AddLogger(l1)
l.AddLogger(l2)
if er := l.Start(); er != nil {
e := errs.Encode(er,nil)
fmt.Printf("\n %s\n%s\n",e,er.Error())
res := pkjson.Pack(entry)
if !res.Ok() {
fmt.Print(errs.Encode(res.Fail(),nil))
return
}
fmt.Println(string(res.Value()))
for i:=0; i<3; i++ {
l.Warn("Esto es un mensage")
}
}
//time.Sleep(1000 * time.Millisecond)
cl()
*/
}

@ -0,0 +1,82 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name err_fields.go
// Created by DEV
// Modified 30/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 errs
import (
"errs/erdata"
"vals/flds"
)
type (
ErrFields struct {
error
flds.AFields
}
)
func (e ErrFields) Unwrap() error {
return e.error }
func (e ErrFields) UnwrapAll() []error {
return nil }
func (e ErrFields) WrapWithInfo (options ...ErrInfoFnc) error {
return WrapWithInfo(e,options...) }
func (e ErrFields) WrapWithCause(cause error) error {
return WrapWithCause(e,cause) }
func (e ErrFields) WrapWithTrace(offset int) error {
return WrapWithTrace(e,offset) }
func (e ErrFields) WrapWithFieldString (name, value string) error {
return WrapWithFieldString(e,name,value) }
func (e ErrFields) WrapWithMessage (msg string) error {
return WrapWithMessage(e,msg) }
func (e ErrFields) String () string {
return string(G.Encoder.EncodeError(e)) }
func (e ErrFields) Collect (collector erdata.Collector) {
}

@ -1,136 +0,0 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name afield.go
// Created by DEV
// Modified 30/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 _deprecated
import (
"time"
"vals/flds"
)
type (
AField struct {
fs *AFields
hp int
}
)
func (f AField) IsValid() bool {
return f.fs.heads[f.hp].pos != -1 }
func (f AField) Name () string {
return f.fs.heads[f.hp].name
}
func (f AField) Kind () flds.Kind {
return f.fs.heads[f.hp].kind
}
func (f AField) Value() any {
if f.fs.heads[f.hp].pos == -1 {
return nil
}
p := f.fs.heads[f.hp].pos
switch f.fs.heads[f.hp].kind {
case flds.KindAny: return f.fs.anys[p]
case flds.KindError: return f.fs.anys[p].(error)
case flds.KindBool: return f.fs.nums[p] != 0
case flds.KindSigned: return f.fs.nums[p]
case flds.KindUnsigned: return uint(f.fs.nums[p])
case flds.KindFloat: return f.fs.floats [p]
case flds.KindString: return f.fs.strings [p]
case flds.KindDate: return f.fs.dates [p]
case flds.KindBinary: return f.fs.binaries[p]
default:
// Handle unknown field type
return nil
}
}
func (f AField) Any () (any,bool) {
return f.Value(), f.hp != -1 }
func (f AField) Bool () (bool,bool) {
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindBool {
return false,false
}
return f.fs.nums[f.fs.heads[f.hp].pos] > 0,true
}
func (f AField) String () (string,bool) {
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindString {
return "",false
}
return f.fs.strings[f.fs.heads[f.hp].pos],true
}
func (f AField) Signed () (int,bool) {
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindSigned {
return 0,false
}
return f.fs.nums[f.fs.heads[f.hp].pos],true
}
func (f AField) Unsigned () (uint,bool) {
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindUnsigned {
return 0,false
}
return uint(f.fs.nums[f.fs.heads[f.hp].pos]),true
}
func (f AField) Date () (time.Time,bool) {
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindDate {
var z time.Time
return z,false
}
return f.fs.dates[f.fs.heads[f.hp].pos],true
}
func (f AField) Time () (time.Time,bool) {
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindTime {
var z time.Time
return z,false
}
return f.fs.dates[f.fs.heads[f.hp].pos],true
}
func (f AField) Error () (error,bool) {
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindError {
return nil,false
}
return f.fs.anys[f.fs.heads[f.hp].pos].(error),true
}
func (f AField) Binary () ([]byte,bool) {
if f.hp != -1 || f.fs.heads[f.hp].kind != flds.KindBinary {
return nil,false
}
return f.fs.binaries[f.fs.heads[f.hp].pos],true
}

@ -1,215 +0,0 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name afields.go
// Created by DEV
// Modified 30/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 _deprecated
import (
"fmt"
"sort"
"time"
"vals/flds"
)
type (
AFields struct {
heads []head
kinds flds.Kind
anys []any
nums []int
floats []float64
strings []string
dates []time.Time
binaries [][]byte
}
AFieldsFnc func(afields *AFields)
AFieldsMapFnc func(field AField) bool
)
func AcquireAFields (options ...AFieldsFnc) *AFields {
return flds.g.pool.Get().init(options) }
func ReleaseAFields (fields *AFields) {
if fields == nil {
return
}
flds.g.pool.Put(fields.Reset())
}
func newAFields () *AFields {
return &AFields{} }
func NewAFields (options ...AFieldsFnc) *AFields {
return newAFields().init(options) }
func (f *AFields) Len () int {
return len(f.heads) }
func (f *AFields) Has (name string) bool {
return f.has(name) != -1 }
func (f *AFields) init (options []AFieldsFnc) *AFields {
for _,o := range options {
o(f)
}
return f
}
func (f *AFields) Reset() *AFields {
f.heads = f.heads[:0]
f.kinds = 0
f.anys = f.anys [:0]
f.nums = f.nums [:0]
f.floats = f.floats [:0]
f.strings = f.strings [:0]
f.dates = f.dates [:0]
f.binaries= f.binaries[:0]
return f
}
func (f *AFields) Kinds() flds.Kind {
return f.kinds }
func (f *AFields) GetField (name string) AField {
return AField{
fs: f,
hp: f.has(name),
}
}
func (f *AFields) Map (mapFn AFieldsMapFnc) {
fl := AField{ fs : f }
for i := 0; i<len(f.heads); i++ {
fl.hp = i
if !mapFn(fl) {
return
}
}
}
func (f *AFields) Sort () {
sort.Slice(f.heads, func(i, j int) bool {
return f.heads[i].name < f.heads[j].name
})
}
func (f *AFields) AddAny (name string, value any) {
switch t := value.(type) {
case string : f.AddString(name,t)
case bool : f.AddBool (name,t)
case int : f.AddSigned(name,t)
case int8 : f.AddSigned(name,int(t))
case int16 : f.AddSigned(name,int(t))
case int32 : f.AddSigned(name,int(t))
case int64 : f.AddSigned(name,int(t))
case uint : f.AddUnsigned(name,t)
case uint8 : f.AddUnsigned(name,uint(t))
case uint16 : f.AddUnsigned(name,uint(t))
case uint32 : f.AddUnsigned(name,uint(t))
case uint64 : f.AddUnsigned(name,uint(t))
case float32 : f.AddFloat(name,float64(t))
case float64 : f.AddFloat(name,t)
case []byte : f.AddBinary(name,t)
case time.Time: f.AddDate(name,t)
default:
f.addField(name, flds.KindAny,len(f.anys)).anys = append(f.anys, value)
}
}
func (f *AFields) AddError(name string, value error) {
f.addField(name, flds.KindError,len(f.anys)).anys = append(f.anys,value) }
func (f *AFields) AddBool (name string, value bool) {
v := 0
if value {
v=1
}
f.addField(name, flds.KindBool,len(f.nums)).nums = append(f.nums,v)
}
func (f *AFields) AddSigned (name string, value int) {
f.addField(name, flds.KindSigned,len(f.nums)).nums = append(f.nums,value) }
func (f *AFields) AddUnsigned(name string, value uint) {
f.addField(name, flds.KindUnsigned,len(f.nums)).nums = append(f.nums,int(value)) }
func (f *AFields) AddFloat(name string, value float64) {
f.addField(name, flds.KindFloat,len(f.floats)).floats = append(f.floats,value) }
func (f *AFields) AddDate (name string, value time.Time) {
f.addField(name, flds.KindDate,len(f.dates)).dates = append(f.dates,value) }
func (f *AFields) AddTime (name string, value time.Time) {
f.addField(name, flds.KindTime,len(f.dates)).dates = append(f.dates,value) }
func (f *AFields) AddString(name string, value string) {
f.addField(name, flds.KindString,len(f.strings)).strings = append(f.strings,value) }
func (f *AFields) AddBinary(name string, value []byte) {
f.addField(name, flds.KindBinary,len(f.binaries)).binaries = append(f.binaries,value) }
func (f *AFields) addField (name string, kind flds.Kind, pos int) *AFields {
for i:=1; f.has(name) == -1; i++ {
name = fmt.Sprintf("fmtNameDuplicated",name,i)
}
f.kinds |= kind
f.heads = append(f.heads, head{
name: name,
kind: kind,
pos : pos,
})
return f
}
func (f *AFields) has (name string) int {
for i,h := range f.heads {
if h.name == name {
return i
}
}
return -1
}

@ -23,6 +23,8 @@
package flds
import "reflect"
const(
kindBits = 16
@ -64,13 +66,28 @@ var (
)
/* deprecated
func checkFieldName (name string) bool {
if name == "" {
panic(G.ErrInvalidName)
func NewAField (name string, value any) AField {
switch t := value.(type) {
case bool :
return NewAFieldBool (name,t)
case []byte : return NewAFieldBinary(name,t)
case string : return NewAFieldString(name,t)
case int : return NewAFieldSigned(name,t)
case int8 : return NewAFieldSigned(name,int(t))
case int16 : return NewAFieldSigned(name,int(t))
case int32 : return NewAFieldSigned(name,int(t))
case int64 : return NewAFieldSigned(name,int(t))
case uint : return NewAFieldUnsigned(name,t)
case uint8 : return NewAFieldUnsigned(name,uint(t))
case uint16 : return NewAFieldUnsigned(name,uint(t))
case uint32 : return NewAFieldUnsigned(name,uint(t))
case uint64 : return NewAFieldUnsigned(name,uint(t))
case uintptr: return NewAFieldUnsigned(name,uint(t))
case float64: return NewAFieldFloat(name,t)
case float32: return NewAFieldFloat(name,float64(t))
case error : return NewAFieldError(name,t)
case reflect.Value : return NewAFieldReflect(name,t)
default:
return NewAFieldAny(name,value)
}
return true
}
*/
}

@ -2,9 +2,9 @@
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name heads.go
// File name afield_binary.go
// Created by DEV
// Modified 30/04/2024
// Modified 01/05/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
@ -21,17 +21,37 @@
// limitations under the License.
// ------------------------------------------------------------------------
package _deprecated
package flds
import "vals/flds"
type (
head struct {
name string
kind flds.Kind
pos int
AFieldBinary struct {
partAField
value []byte
}
)
func NewAFieldBinary (name string, value []byte) *AFieldBinary {
return &AFieldBinary{
partAField: makePartAField(name),
value : value } }
func (_ AFieldBinary) Kind () Kind {
return KindBinary }
func (f AFieldBinary) Value() any {
return f.value }
func (f AFieldBinary) Any () (any,bool) {
return f.value,true }
func (f AFieldBinary) Binary() ([]byte,bool) {
return f.value,true }

@ -41,7 +41,7 @@ func NewAFieldBool (name string, value bool) *AFieldBool {
func (_ AFieldBool) Kind () Kind {
return KindSigned }
return KindBool }
func (f AFieldBool) Value() any {
return f.value }

@ -23,7 +23,9 @@
package flds
import "sort"
import (
"sort"
)
type (
@ -69,6 +71,16 @@ func (f AFields) AddField (field AField) AFields {
return f
}
func (f AFields) SetField (field AField) AFields {
if field == nil {
return f
}
if p := f.has(field.Name()); p != -1 {
return append(append(f[:p],field), f[p+1:]...)
}
return append(f,field)
}
func (f AFields) DelField (name string) AFields {
if p := f.has(name); p != -1 {
return append(f[:p],f[p+1:]...)

@ -35,7 +35,9 @@ func AFieldBuildPack(obuilder apacks.ObjectPackBuilder, field flds.AField) {
n := field.Name()
switch field.Kind() {
case flds.KindAny : obuilder.FieldAny(field.Name(),field.Value(),0)
case flds.KindBool : v,_ := field.Bool(); obuilder.FieldBool (n,v,0)
case flds.KindBool :
v,_ := field.Bool()
obuilder.FieldBool (n,v,0)
case flds.KindSigned : v,_ := field.Signed(); obuilder.FieldInt64 (n,int64 (v),0)
case flds.KindUnsigned: v,_ := field.Unsigned();obuilder.FieldUInt64 (n,uint64(v),0)
case flds.KindFloat : v,_ := field.Float(); obuilder.FieldFloat64(n,v,0)

@ -46,7 +46,7 @@ func (f AFieldsObjectPacker) BuildPack (packer apacks.ValuePacker) error {
func AFieldsAddToPack(fbuilder apacks.ObjectPackBuilder, fields flds.AFields) {
func AddAFieldsToPack(fbuilder apacks.ObjectPackBuilder, fields flds.AFields) {
for _, fl := range fields {
AFieldBuildPack(fbuilder, fl)
}

Loading…
Cancel
Save

Powered by TurnKey Linux.