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

master
DEV 2 years ago
parent 62bab50f11
commit 5fb433f607

@ -27,7 +27,7 @@ package blds
type (
FieldBuilder interface {
FieldsBuilder interface {
BuildField (builder ObjectBuilder)
}

@ -90,7 +90,7 @@ func CollectErrorFields (obuilder blds.ObjectBuilder, err error) {
rt = rt.Elem()
}
if ec,is := err.(blds.FieldBuilder); is {
if ec,is := err.(blds.FieldsBuilder); is {
ec.BuildField(obuilder)
return
}

@ -24,12 +24,18 @@
package erstfy
import "sync"
import (
"core/tups"
"sync"
)
const (
labelError string = "error"
labelSep string = " : "
)
@ -50,7 +56,46 @@ var (
func DefaultStringer() *Stringer {
g.once.Do(func(){
g.stringer = NewStringer()
g.stringer = NewStringer(
WithLabels(true,
*tups.NewStringTuple("message","message"),
*tups.NewStringTuple("info" ,"info"),
*tups.NewStringTuple("date" ,"date"),
*tups.NewStringTuple("desc" ,"desc"),
*tups.NewStringTuple("time" ,"time"),
*tups.NewStringTuple("help" ,"help"),
*tups.NewStringTuple("link" ,"link"),
*tups.NewStringTuple("cause", "cause"),
*tups.NewStringTuple("trace:", "trace,"),
*tups.NewStringTuple("param:", "param,"),
*tups.NewStringTuple("source", "source"),
*tups.NewStringTuple("user" ,"user" ),
),
// TraceBegin = "tb"
// TraceEnd = "te"
// ErrorsBegin = "eb"
// ErrorsEnd = "ee"
WithLines(
*tups.NewStringTuple("tb","\tBEGIN TRACE-----------------------------------\n"),
*tups.NewStringTuple("te","\t-------------------------------------TRACE END\n"),
*tups.NewStringTuple("eb","\tBEGIN ERRORS----------------------------------\n"),
*tups.NewStringTuple("ee","\t------------------------------------ERRORS END\n"),
),
// labelFmt = "lb"
// lineErrorFmt = "er"
// lineTextFmt = "tx"
WithFormats(
*tups.NewStringTuple("lb","\t%-10s : "),
*tups.NewStringTuple("er","ERROR %s\n"),
*tups.NewStringTuple("tx","\t%s\n"),
),
// Transformadores de etiquetas y texto
// ❓ Usarlo o no usarlo
//WithLabelTransformers(strs.TransformFnc(strs.ToLowerCamel)),
)
})
return g.stringer
}

@ -27,6 +27,7 @@ package erstfy
import (
"bfrs"
"bytes"
"core/tups"
"errs/stack"
"fmt"
"strings"
@ -36,23 +37,21 @@ import (
type (
Stringer struct {
labelSep string
lineLabelFmt string
labelFmt string
lineErrorFmt string
lineTextFmt string
labelTrans strs.Transformers
labels map[string]string
lineLabelFmt string
labels map[string]string
useLabels bool
lineErrorFmt string
lineTextFmt string
lineTraceBegin string
lineTraceEnd string
lineErrorsBegin string
lineErrorsEnd string
labelTrans strs.Transformers
trans strs.Transformers
}
@ -63,38 +62,13 @@ type (
func NewStringer (options ...StringerFnc) *Stringer {
s := &Stringer{
//labels : *newLabels(),
useLabels: true,
labels : map[string]string{
"message":"message",
"info" : "info",
"date" : "date",
"desc" : "desc",
"time" : "time",
"help" : "help",
"link" : "link",
"cause" : "cause",
"trace:": "trace,",
"param:": "param,",
"source": "source",
"user" : "user" },
labelSep: labelSep,
labelFmt: "\t%-10s" + labelSep,
lineTextFmt : "\t%s\n",
lineErrorFmt : "ERROR %s\n",
lineTraceBegin : "\tBEGIN TRACE-----------------------------------\n",
lineTraceEnd : "\t-------------------------------------TRACE END\n",
lineErrorsBegin : "\tBEGIN ERRORS----------------------------------\n",
lineErrorsEnd : "\t------------------------------------ERRORS END\n",
useLabels : true,
labels : make(map[string]string),
labelFmt : "\t%-10s : ",
lineErrorFmt : "ERROR %s\n",
lineTextFmt : "\t%s\n",
}
s.lineLabelFmt = s.labelFmt + "%s\n"
for _,o := range options {
o(s)
}
@ -227,3 +201,72 @@ func (stg *Stringer) GetLabel (label string) string {
func (stg *Stringer) FormatLabel (label string) string {
return fmt.Sprintf(stg.labelFmt, stg.labelTrans.Transform(stg.GetLabel(label))) }
func WithLabelTransformers (transformer ... strs.Transformer) StringerFnc {
return func(s *Stringer) {
s.labelTrans = append(s.labelTrans, transformer ...) } }
func WithTransformers (transformer ... strs.Transformer) StringerFnc {
return func(s *Stringer) {
s.trans = append(s.trans, transformer ...) } }
func WithLabels (use bool, label ... tups.StringTuple) StringerFnc {
return func(s *Stringer) {
s.useLabels = use
for _,l:=range label {
s.labels[l.A]=l.B
}
}
}
// WithLines
// TraceBegin = "tb"
// TraceEnd = "te"
// ErrorsBegin = "eb"
// ErrorsEnd = "ee"
func WithLines (line ...tups.StringTuple) StringerFnc {
return func(s *Stringer) {
for _, l := range line {
switch l.A {
case "tb" : s.lineTraceBegin = l.B
case "te" : s.lineTraceEnd = l.B
case "eb" : s.lineErrorsBegin= l.B
case "ee" : s.lineErrorsEnd = l.B
}
}
}
}
// WithFormats
// labelFmt = "lb"
// lineErrorFmt = "er"
// lineTextFmt = "tx"
func WithFormats(format ...tups.StringTuple) StringerFnc {
return func(s *Stringer) {
for _, l := range format {
switch l.A {
case "lb": s.labelFmt = l.B
case "er": s.lineErrorFmt = l.B
case "tx": s.lineTextFmt = l.B
}
}
}
}

@ -34,7 +34,7 @@ type (
Field interface {
bfrs.Appender
blds.FieldBuilder
blds.FieldsBuilder
Kind () Kind
Name () string

@ -0,0 +1,41 @@
// ------------------------------------------------------------------------
// 🚀 Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name g_key_value.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 tups
type (
GTuple[K comparable, T any] struct {
A K
B T
}
)
func NewGTuple [K comparable, T any](a K, b T) *GTuple[K,T] {
return &GTuple[K,T]{
A : a,
B : b } }

@ -0,0 +1,46 @@
// ------------------------------------------------------------------------
// 🚀 Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name stringstring.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 tups
type (
StringTuple struct {
A string
B string
}
)
func NewStringTuple (a, b string) *StringTuple {
return &StringTuple{
A : a,
B : b } }
func (t StringTuple) ValueA () string {
return t.A }
func (t StringTuple) ValueB () string {
return t.B }

@ -0,0 +1,38 @@
// ------------------------------------------------------------------------
// 🚀 Project active3
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name tuple.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 tups
type (
Tupler [K any, V any] interface {
ValueA () K
ValueB () V
}
)

@ -74,7 +74,7 @@ var (
}
g = struct {
acronyms *reps.GRepo[string,string]
acronyms *reps.GRepo[string,string]
}{
acronyms: reps.NewGRepo[string,string]("",false),
}

Loading…
Cancel
Save

Powered by TurnKey Linux.