From b714acbc5b562940b87467e11fcfc40519920793 Mon Sep 17 00:00:00 2001 From: DEV Date: Thu, 25 Apr 2024 02:19:21 +0200 Subject: [PATCH] Empezado la adaptacion del modulos de logs --- app/main.go | 127 +----------- core/btes/tokens/atokenizer.go | 13 +- core/crypts/decrypter.go | 2 - core/crypts/encrypter.go | 5 - core/mems/pool.go | 31 +-- core/{rsts => results}/bytes.go | 0 core/{rsts => results}/g_result.go | 0 core/results/go.mod | 3 + core/{rsts => results}/int.go | 0 core/{rsts => results}/result.go | 0 core/{rsts => results}/string.go | 0 core/rsts/go.mod | 3 - core/syncs/abool.go | 109 ++++++++++ core/syncs/aduration.go | 117 +++++++++++ core/syncs/aerror.go | 90 ++++++++ core/syncs/aint32.go | 121 +++++++++++ core/syncs/aint64.go | 121 +++++++++++ core/syncs/ananos.go | 155 ++++++++++++++ core/syncs/auint32.go | 121 +++++++++++ core/syncs/auint64.go | 121 +++++++++++ core/syncs/b32_aint.go | 64 ++++++ core/syncs/b32_uint.go | 64 ++++++ core/syncs/b64_int.go | 124 +++++++++++ core/syncs/b64_uint.go | 124 +++++++++++ core/syncs/nop_locker.go | 10 +- core/syncs/pool_ops.go | 69 ------- core/syncs/{pool.go => pools/g_pool.go} | 61 +++++- core/syncs/{ => pools}/pool_call_sizes.go | 2 +- core/syncs/{ => pools}/pool_stats.go | 2 +- core/syncs/{ => pools}/pool_stats_info.go | 2 +- core/syncs/queue/g_queue.go | 85 ++++++++ core/syncs/works/pool.go | 8 +- go.work | 6 +- {logs => hecate}/active.go | 46 +++++ hecate/aggregator.go | 53 +++++ hecate/alogger.go | 90 ++++++++ hecate/appender.go | 40 ++++ hecate/entry.go | 136 +++++++++++++ hecate/entry_logger.go | 41 ++++ {logs => hecate}/err_logs.go | 0 hecate/filter.go | 105 ++++++++++ hecate/filters.go | 116 +++++++++++ hecate/go.mod | 3 + {logs => hecate}/level.go | 13 +- logs/entry.go => hecate/log.go | 14 +- {logs => hecate}/loggable.go | 0 {logs => hecate}/logger.go | 0 hecate/logger_core.go | 52 +++++ hecate/logger_level.go | 93 +++++++++ hecate/scope.go | 192 ++++++++++++++++++ hecate/scope_mode.go | 56 +++++ hecate/scopes.go | 63 ++++++ {logs => hecate}/state.go | 0 logs/go.mod | 3 - packs/go.mod | 7 - packs/pjson/list_pack_builder.go | 80 -------- {packs => proteus}/active.go | 6 +- {packs => proteus}/builder.go | 2 +- {packs => proteus}/err_packs.go | 2 +- {packs => proteus}/flags.go | 2 +- {packs => proteus}/fold.go | 2 +- proteus/go.mod | 7 + {packs => proteus}/list_pack_builder.go | 2 +- {packs => proteus}/map_pack_builder.go | 2 +- {packs => proteus}/object_pack_builder.go | 2 +- {packs => proteus}/packer.go | 2 +- {packs => proteus}/pjson/active.go | 5 +- {packs => proteus}/pjson/json_packer.go | 120 +++++------ proteus/pjson/list_pack_builder.go | 80 ++++++++ {packs => proteus}/pjson/map_pack_builder.go | 46 ++--- .../pjson/object_pack_builder.go | 40 ++-- {packs => proteus}/pjson/rpacker.go | 20 +- {packs => proteus}/pjson/rpacker_interface.go | 2 +- {packs => proteus}/pjson/rpacker_key.go | 10 +- {packs => proteus}/pjson/rpacker_list.go | 10 +- {packs => proteus}/pjson/rpacker_map.go | 6 +- {packs => proteus}/pjson/rpacker_map_entry.go | 2 +- {packs => proteus}/pjson/rpacker_object.go | 20 +- .../pjson/rpacker_object_field.go | 4 +- {packs => proteus}/pjson/rpacker_pointer.go | 2 +- {packs => proteus}/pjson/rpacker_value.go | 4 +- {packs => proteus}/state.go | 8 +- {packs => proteus}/value_packer.go | 2 +- 83 files changed, 2865 insertions(+), 508 deletions(-) rename core/{rsts => results}/bytes.go (100%) rename core/{rsts => results}/g_result.go (100%) create mode 100644 core/results/go.mod rename core/{rsts => results}/int.go (100%) rename core/{rsts => results}/result.go (100%) rename core/{rsts => results}/string.go (100%) delete mode 100644 core/rsts/go.mod create mode 100644 core/syncs/abool.go create mode 100644 core/syncs/aduration.go create mode 100644 core/syncs/aerror.go create mode 100644 core/syncs/aint32.go create mode 100644 core/syncs/aint64.go create mode 100644 core/syncs/ananos.go create mode 100644 core/syncs/auint32.go create mode 100644 core/syncs/auint64.go create mode 100644 core/syncs/b32_aint.go create mode 100644 core/syncs/b32_uint.go create mode 100644 core/syncs/b64_int.go create mode 100644 core/syncs/b64_uint.go delete mode 100644 core/syncs/pool_ops.go rename core/syncs/{pool.go => pools/g_pool.go} (61%) rename core/syncs/{ => pools}/pool_call_sizes.go (98%) rename core/syncs/{ => pools}/pool_stats.go (98%) rename core/syncs/{ => pools}/pool_stats_info.go (99%) create mode 100644 core/syncs/queue/g_queue.go rename {logs => hecate}/active.go (63%) create mode 100644 hecate/aggregator.go create mode 100644 hecate/alogger.go create mode 100644 hecate/appender.go create mode 100644 hecate/entry.go create mode 100644 hecate/entry_logger.go rename {logs => hecate}/err_logs.go (100%) create mode 100644 hecate/filter.go create mode 100644 hecate/filters.go create mode 100644 hecate/go.mod rename {logs => hecate}/level.go (96%) rename logs/entry.go => hecate/log.go (88%) rename {logs => hecate}/loggable.go (100%) rename {logs => hecate}/logger.go (100%) create mode 100644 hecate/logger_core.go create mode 100644 hecate/logger_level.go create mode 100644 hecate/scope.go create mode 100644 hecate/scope_mode.go create mode 100644 hecate/scopes.go rename {logs => hecate}/state.go (100%) delete mode 100644 logs/go.mod delete mode 100644 packs/go.mod delete mode 100644 packs/pjson/list_pack_builder.go rename {packs => proteus}/active.go (96%) rename {packs => proteus}/builder.go (98%) rename {packs => proteus}/err_packs.go (98%) rename {packs => proteus}/flags.go (99%) rename {packs => proteus}/fold.go (99%) create mode 100644 proteus/go.mod rename {packs => proteus}/list_pack_builder.go (99%) rename {packs => proteus}/map_pack_builder.go (99%) rename {packs => proteus}/object_pack_builder.go (99%) rename {packs => proteus}/packer.go (98%) rename {packs => proteus}/pjson/active.go (94%) rename {packs => proteus}/pjson/json_packer.go (61%) create mode 100644 proteus/pjson/list_pack_builder.go rename {packs => proteus}/pjson/map_pack_builder.go (68%) rename {packs => proteus}/pjson/object_pack_builder.go (82%) rename {packs => proteus}/pjson/rpacker.go (67%) rename {packs => proteus}/pjson/rpacker_interface.go (93%) rename {packs => proteus}/pjson/rpacker_key.go (95%) rename {packs => proteus}/pjson/rpacker_list.go (86%) rename {packs => proteus}/pjson/rpacker_map.go (93%) rename {packs => proteus}/pjson/rpacker_map_entry.go (98%) rename {packs => proteus}/pjson/rpacker_object.go (90%) rename {packs => proteus}/pjson/rpacker_object_field.go (97%) rename {packs => proteus}/pjson/rpacker_pointer.go (95%) rename {packs => proteus}/pjson/rpacker_value.go (90%) rename {packs => proteus}/state.go (96%) rename {packs => proteus}/value_packer.go (99%) diff --git a/app/main.go b/app/main.go index bc461bb..e75d4c9 100644 --- a/app/main.go +++ b/app/main.go @@ -1,135 +1,28 @@ package main import ( - "errs" - "errs/collects" - "errs/fjson" - "errs/ftext" - "errs/stack" "fmt" - "time" ) - -func printTrace (s stack.Trace) { - lf := s.Frames() - for i,f := range lf { - fmt.Printf("%d file %s line %d %s\n",i,f.File,f.LineNumber,f.FuncName) - } -} - - -func GenerateBinaryString() string { - binaryString := "" - for c := 0; c < 255; c++ { - if ('a' <= byte(c) && byte(c) <= 'z') || ('A' <= byte(c) && byte(c) <= 'Z') || byte(c) == '@' { - binaryString += "1" - } else { - binaryString += "0" - } - } - return binaryString -} - - - - -type ( - - MiCustomErr struct { - error - ms string - } -) - -func (c MiCustomErr) Message() string { - return "esto es un custom werro" -} - -func (c MiCustomErr) Code() string { - return "custom-code" -} - -func (c MiCustomErr) Int () int { - return 33423 -} - - - - -func (c MiCustomErr) Error () string { - return "ERRRROPROO" -} - -func (c MiCustomErr) Unwrap () error { - return c.error -} - -func (c MiCustomErr) Collect (collector collects.Collector) { - collector.AddFieldInt("UnInt",c.Int()) - collector.AddFieldFloat("UnFloat",34.33) - collector.AddFieldAny("UnoCualquiera",struct { - A string - B int - T time.Time - F float64 - }{ - A : "UUnA", - B : 3, - T : time.Now(), - F : 2.343, - }) -} - - -func printCollection (ec collects.ErrorCollection) { - if ec.Invalid != nil { - fmt.Printf("INvalid %s\n", ec.Invalid.Error()) - } - ec.Fields.Sort() - - fmt.Printf("Error: %s\n",ec.ErrStr) - fmt.Printf("Types: %d\n",len(ec.Types)) - for _,t := range ec.Types { - fmt.Printf("\tWrap Type : %s\n",t.String()) - } - fmt.Printf("Fields: \n") - for _,h := range ec.Fields.GetHeads() { - fmt.Printf("\t%s : %v\n",h.Name) - } - fmt.Printf("Causes: \n") - for _,c := range ec.Causes { - printCollection(c) - } -} - - func main() { - me := errs.WrapWithCause(errs.WrapWithInfo(MiCustomErr{}, - errs.ErrInfoWithInfo("Mi mensaje")),errs.ErrCode("UnERRORito")) - - mu := errs.NewErrMulti( - errs.ErrCode("UnError"), - errs.ErrCode("UnOtro"), - me, - ) + filters := logs.NewFilters() + filters.AddFilterAllowed(logs.NewFilter("1",func(e *logs.Entry) bool { + fmt.Println("UNO FILTER") + return e.Level.Has(logs.LevelWarn) + })) - //printCollection(*collr.NewErrorCollection(me).Collect(true,true,true)) + filters.AddFilterAllowed(logs.NewFilter("2",func(e *logs.Entry) bool { + fmt.Println("DS FILTER") + return e.Level.Has(logs.LevelDebug) + })) - f := ftext.DefaultFormatter() - j := fjson.DefaultFormatter() - - fmt.Print(string(f.FormatError(errs.WrapWithTrace(mu,1)))) - - fmt.Print(string(j.FormatError(errs.WrapWithTrace(mu,1)))) + fmt.Printf("Pasado %v\n",filters.Filter(logs.NewEntry(nil,logs.LevelWarn.Add(logs.LevelDebug),"",nil))) } - - diff --git a/core/btes/tokens/atokenizer.go b/core/btes/tokens/atokenizer.go index 15cf084..7d066c0 100644 --- a/core/btes/tokens/atokenizer.go +++ b/core/btes/tokens/atokenizer.go @@ -64,18 +64,17 @@ type ( ) - -// NewTokenizerCore +// NewATokenizer // Function constructor -> ATokenizer // // -func NewTokenizerCore(options ...ATokenizerFnc) *ATokenizer { +func NewATokenizer(options ...ATokenizerFnc) *ATokenizer { tk := &ATokenizer{ aTokenizerChars : *newATokenizerChars(), - MinLenToken : tokenMinLen, - MaxLenToken : tokenMaxLen, - MinLenTopic : topicMinLen, - MaxLenTopic : topicMaxLen, + MinLenToken : tokenMinLen, + MaxLenToken : tokenMaxLen, + MinLenTopic : topicMinLen, + MaxLenTopic : topicMaxLen, MinTokens : topicMinTokens, MaxTokens : topicMaxTokens, MatchBuilder : matchs.NopBuilder{}, diff --git a/core/crypts/decrypter.go b/core/crypts/decrypter.go index 93e0b2e..f35a3b1 100644 --- a/core/crypts/decrypter.go +++ b/core/crypts/decrypter.go @@ -23,8 +23,6 @@ package crypts -import "rsts" - type ( Decrypter interface { diff --git a/core/crypts/encrypter.go b/core/crypts/encrypter.go index b954654..d87a5a5 100644 --- a/core/crypts/encrypter.go +++ b/core/crypts/encrypter.go @@ -23,11 +23,6 @@ package crypts -import ( - - "rsts" -) - type ( diff --git a/core/mems/pool.go b/core/mems/pool.go index 067cf32..7b6f103 100644 --- a/core/mems/pool.go +++ b/core/mems/pool.go @@ -27,7 +27,7 @@ import ( "sort" "sync" "sync/atomic" - "syncs" + "syncs/pools" ) @@ -35,7 +35,7 @@ import ( type ( Pool struct { - syncs.PoolStatsInfo + pools.PoolStatsInfo inner sync.Pool @@ -54,7 +54,14 @@ type ( ) func NewPool(options ...PoolFnc) *Pool { - return applyBufferPoolOptions(&Pool{percentile: poolPercentile}, options...) } + p :=&Pool { + percentile: poolPercentile, + } + for _,o := range options { + o(p) + } + return p +} func (p *Pool) MaxSize() uint64 { @@ -104,12 +111,12 @@ func (p *Pool) calibrate() { if atomic.CompareAndSwapUint64(&p.calibra, 0, 1) { return } - ar := make(syncs.PoolCallSizes, 0, poolSteps) + ar := make(pools.PoolCallSizes, 0, poolSteps) cs := uint64(0) for i := uint64(0); i < poolSteps; i++ { cl := atomic.SwapUint64(&p.calls[i], 0) cs += cl - ar = append(ar, syncs.PoolCallSize{ + ar = append(ar, pools.PoolCallSize{ Calls: cl, Size: minSize << i}) } @@ -155,19 +162,13 @@ func index(n int) int { -func applyBufferPoolOptions (b *Pool, options ...PoolFnc) *Pool { - for _,o := range options { - o(b) - } - return b -} func WithMaxPercentile(percentile float32) PoolFnc { - return func(b *Pool) { - b.percentile = percentile } } + return func(p *Pool) { + p.percentile = percentile } } func CallsThreshold(threshold uint64) PoolFnc { - return func(b *Pool) { - atomic.StoreUint64(&b.threshold, threshold) } } + return func(p *Pool) { + atomic.StoreUint64(&p.threshold, threshold) } } diff --git a/core/rsts/bytes.go b/core/results/bytes.go similarity index 100% rename from core/rsts/bytes.go rename to core/results/bytes.go diff --git a/core/rsts/g_result.go b/core/results/g_result.go similarity index 100% rename from core/rsts/g_result.go rename to core/results/g_result.go diff --git a/core/results/go.mod b/core/results/go.mod new file mode 100644 index 0000000..61b1e16 --- /dev/null +++ b/core/results/go.mod @@ -0,0 +1,3 @@ +module results + +go 1.22 diff --git a/core/rsts/int.go b/core/results/int.go similarity index 100% rename from core/rsts/int.go rename to core/results/int.go diff --git a/core/rsts/result.go b/core/results/result.go similarity index 100% rename from core/rsts/result.go rename to core/results/result.go diff --git a/core/rsts/string.go b/core/results/string.go similarity index 100% rename from core/rsts/string.go rename to core/results/string.go diff --git a/core/rsts/go.mod b/core/rsts/go.mod deleted file mode 100644 index fa945a1..0000000 --- a/core/rsts/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module rsts - -go 1.22 diff --git a/core/syncs/abool.go b/core/syncs/abool.go new file mode 100644 index 0000000..fc89c59 --- /dev/null +++ b/core/syncs/abool.go @@ -0,0 +1,109 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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 syncs + +import ( + "sync/atomic" +) + +type ( + + // ABool + // Type: Struct + // Desc: Atomic Bool, estructura para realizar operaciones atomicas + // sobre un valor de tipo Bool + // + ABool struct { + + // value: valor sobre el que se realizaran las operaciones + // atomicas. + // + value uint32 + } +) + +// NewABool +// Desc: Función constructor para ABool +// +// Prms: val, valor inicial +// Rets: Puntero al nuevo objeto creado. +// +func NewABool(val bool) *ABool { return &ABool{value: boolAsUint32(val)} } + +// ABool.Get +// Desc: +// Rets: +// +func (b *ABool) Get() bool { return atomic.LoadUint32(&b.value) == 1 } + +// ABool.Set +// Desc: +// Prms: +// +func (b *ABool) Set(val bool) { atomic.StoreUint32(&b.value, boolAsUint32(val)) } + +// ABool.Swap +// Desc: +// Prms: +// +func (b *ABool) Swap(new bool) bool { return atomic.SwapUint32(&b.value, boolAsUint32(new)) == 1 } + +// ABool.CAS +// Desc: +// Prms: +// Rets: +// +func (b *ABool) CAS(old, new bool) bool { + return atomic.CompareAndSwapUint32(&b.value, boolAsUint32(old), boolAsUint32(new)) +} + +// boolAsUint32 +// Desc: Convierte un valor de tipo bool a uint32 +// Prms: val, valor a convertir +// Rets: uint32, El valor segun sea true = 1 o +// false = * +// +func boolAsUint32(val bool) uint32 { + if val { + return 1 + } + return 0 +} + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/aduration.go b/core/syncs/aduration.go new file mode 100644 index 0000000..360f74d --- /dev/null +++ b/core/syncs/aduration.go @@ -0,0 +1,117 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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 syncs + +import ( + "sync/atomic" + "time" +) + +type ( + + // ADuration + // Type: Struct + // + // Desc: + // + // + ADuration struct { + value int64 + } +) + +// NewADuration +// Desc: Función constructor para ADuration +// +// Prms: val, valor inicial +// Rets: Puntero al nuevo objeto creado. +// +func NewADuration(val time.Duration) *ADuration { return &ADuration{value: int64(val)} } + +// ADuration.Get +// Desc: +// Prms: +// Rets: +// +func (i *ADuration) Get() time.Duration { return time.Duration(atomic.LoadInt64(&i.value)) } + +// ADuration.Set +// Desc: +// Prms: +// Rets: +// +func (i *ADuration) Set(val time.Duration) { atomic.StoreInt64(&i.value, int64(val)) } + +// ADuration.Swap +// Desc: +// Prms: +// Rets: +// +func (i *ADuration) Swap(new time.Duration) time.Duration { + return time.Duration(atomic.SwapInt64(&i.value, int64(new))) +} + +// ADuration.Add +// Desc: +// Prms: +// Rets: +// +func (i *ADuration) Add(dlt time.Duration) time.Duration { + return time.Duration(atomic.AddInt64(&i.value, int64(dlt))) +} + +// ADuration.Sub +// Desc: +// Prms: +// Rets: +// +func (i *ADuration) Sub(dlt time.Duration) time.Duration { + return time.Duration(atomic.AddInt64(&i.value, int64(-dlt))) +} + +// ADuration.CAS +// Desc: +// Prms: +// Rets: +// +func (i *ADuration) CAS(old, new time.Duration) bool { + return atomic.CompareAndSwapInt64(&i.value, int64(old), int64(new)) +} + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/aerror.go b/core/syncs/aerror.go new file mode 100644 index 0000000..953698d --- /dev/null +++ b/core/syncs/aerror.go @@ -0,0 +1,90 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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 syncs + +import ( + "sync/atomic" +) + +type ( + + // AError + // Type: Struct + // Desc: + // + // + AError struct { + value atomic.Value + } +) + +// NewAError +// Desc: Función constructor para AError +// +// Prms: val, valor inicial +// Rets: Puntero al nuevo objeto creado. +// +func NewAError(err error) *AError { + ae := &AError{} + if err != nil { + ae.value.Store(err) + } + return ae +} + +// AError.Set +// Desc: +// Prms: +// Rets: +// +func (a *AError) Set(err error) { a.value.Store(err) } + +// AError.Get +// Desc: +// Prms: +// Rets: +// +func (a *AError) Get() error { + if vl := a.value.Load(); vl != nil { + return vl.(error) + } + return nil +} + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/aint32.go b/core/syncs/aint32.go new file mode 100644 index 0000000..8a45b04 --- /dev/null +++ b/core/syncs/aint32.go @@ -0,0 +1,121 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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 syncs + +import ( + "sync/atomic" +) + +type ( + + // AInt32 + // Type: Struct + // Desc: + // + // + AInt32 struct { + value int32 + } +) + +// NewAInt32 +// Desc: Función constructor para AInt32 +// +// Prms: val, valor inicial +// Rets: Puntero al nuevo objeto creado. +// +func NewAInt32(val int32) *AInt32 { return &AInt32{value: val} } + +// AInt32.Get +// Desc: +// Prms: +// Rets: +// +func (i *AInt32) Get() int32 { return atomic.LoadInt32(&i.value) } + +// AInt32.Set +// Desc: +// Prms: +// Rets: +// +func (i *AInt32) Set(val int32) { atomic.StoreInt32(&i.value, val) } + +// AInt32.Swap +// Desc: +// Prms: +// Rets: +// +func (i *AInt32) Swap(new int32) int32 { return atomic.SwapInt32(&i.value, new) } + +// AInt32.Add +// Desc: +// Prms: +// Rets: +// +func (i *AInt32) Add(dlt int32) int32 { return atomic.AddInt32(&i.value, dlt) } + +// AInt32.Sub +// Desc: +// Prms: +// Rets: +// +func (i *AInt32) Sub(dlt int32) int32 { return atomic.AddInt32(&i.value, -dlt) } + +// AInt32.Inc +// Desc: +// Prms: +// Rets: +// +func (i *AInt32) Inc() int32 { return i.Add(1) } + +// AInt32.Dec +// Desc: +// Prms: +// Rets: +// +func (i *AInt32) Dec() int32 { return i.Add(-1) } + +// AInt32.CAS +// Desc: +// Prms: +// Rets: +// +func (i *AInt32) CAS(old, new int32) bool { return atomic.CompareAndSwapInt32(&i.value, old, new) } + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/aint64.go b/core/syncs/aint64.go new file mode 100644 index 0000000..cde1159 --- /dev/null +++ b/core/syncs/aint64.go @@ -0,0 +1,121 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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 syncs + +import ( + "sync/atomic" +) + +type ( + + // AInt64 + // Type: Struct + // Desc: + // + // + AInt64 struct { + value int64 + } +) + +// NewAInt64 +// Desc: Función constructor para AInt64 +// +// Prms: val, valor inicial +// Rets: Puntero al nuevo objeto creado. +// +func NewAInt64(val int64) *AInt64 { return &AInt64{value: val} } + +// AInt64.Get +// Desc: +// Prms: +// Rets: +// +func (i *AInt64) Get() int64 { return atomic.LoadInt64(&i.value) } + +// AInt64.Set +// Desc: +// Prms: +// Rets: +// +func (i *AInt64) Set(val int64) { atomic.StoreInt64(&i.value, val) } + +// AInt64.Swap +// Desc: +// Prms: +// Rets: +// +func (i *AInt64) Swap(new int64) int64 { return atomic.SwapInt64(&i.value, new) } + +// AInt64.Add +// Desc: +// Prms: +// Rets: +// +func (i *AInt64) Add(dlt int64) int64 { return atomic.AddInt64(&i.value, dlt) } + +// AInt64.Sub +// Desc: +// Prms: +// Rets: +// +func (i *AInt64) Sub(dlt int64) int64 { return atomic.AddInt64(&i.value, -dlt) } + +// AInt64.Inc +// Desc: +// Prms: +// Rets: +// +func (i *AInt64) Inc() int64 { return i.Add(1) } + +// AInt64.Dec +// Desc: +// Prms: +// Rets: +// +func (i *AInt64) Dec() int64 { return i.Add(-1) } + +// AInt64.CAS +// Desc: +// Prms: +// Rets: +// +func (i *AInt64) CAS(old, new int64) bool { return atomic.CompareAndSwapInt64(&i.value, old, new) } + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/ananos.go b/core/syncs/ananos.go new file mode 100644 index 0000000..9a04265 --- /dev/null +++ b/core/syncs/ananos.go @@ -0,0 +1,155 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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 syncs + +import ( + "sync/atomic" + "time" +) + +type ( + + // ANanos + // Type: Struct + // Desc: + // + // + ANanos struct { + value int64 + } +) + +// NewANanos +// Desc: Función constructor para ANanos +// +// Prms: val, valor inicial +// Rets: Puntero al nuevo objeto creado. +// +func NewANanos(val time.Duration) *ANanos { return &ANanos{value: int64(val)} } + +// ANanos.Get +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) Get() time.Duration { return time.Duration(atomic.LoadInt64(&i.value)) } + +// ANanos.Set +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) Set(val time.Duration) { atomic.StoreInt64(&i.value, int64(val)) } + +// ANanos.Swap +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) Swap(new time.Duration) time.Duration { + return time.Duration(atomic.SwapInt64(&i.value, int64(new))) +} + +// ANanos.Add +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) Add(dlt time.Duration) time.Duration { + return time.Duration(atomic.AddInt64(&i.value, int64(dlt))) +} + +// ANanos.Sub +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) Sub(dlt time.Duration) time.Duration { + return time.Duration(atomic.AddInt64(&i.value, int64(-dlt))) +} + +// ANanos.CAS +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) CAS(old, new time.Duration) bool { + return atomic.CompareAndSwapInt64(&i.value, int64(old), int64(new)) +} + +// ANanos.GetTime +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) GetTime() time.Time { return time.Unix(0, atomic.LoadInt64(&i.value)) } + +// ANanos.SetTime +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) SetTime(val time.Time) { atomic.StoreInt64(&i.value, val.UnixNano()) } + +// ANanos.GetNanos +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) GetNanos() int64 { return atomic.LoadInt64(&i.value) } + +// ANanos.SetNanos +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) SetNanos(val int64) { atomic.StoreInt64(&i.value, val) } + +// ANanos.SetNow +// Desc: +// Prms: +// Rets: +// +func (i *ANanos) SetNow() time.Time { + nw := time.Now() + i.SetTime(nw) + return nw +} + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/auint32.go b/core/syncs/auint32.go new file mode 100644 index 0000000..d148507 --- /dev/null +++ b/core/syncs/auint32.go @@ -0,0 +1,121 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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 syncs + +import ( + "sync/atomic" +) + +type ( + + // AUInt32 + // Type: Struct + // Desc: + // + // + AUInt32 struct { + value uint32 + } +) + +// NewAUInt32 +// Desc: Función constructor para AUInt32 +// +// Prms: val, valor inicial +// Rets: Puntero al nuevo objeto creado. +// +func NewAUInt32(val uint32) *AUInt32 { return &AUInt32{value: val} } + +// AUInt32.Get +// Desc: +// Prms: +// Rets: +// +func (u *AUInt32) Get() uint32 { return atomic.LoadUint32(&u.value) } + +// AUInt32.Set +// Desc: +// Prms: +// Rets: +// +func (u *AUInt32) Set(val uint32) { atomic.StoreUint32(&u.value, val) } + +// AUInt32.Swap +// Desc: +// Prms: +// Rets: +// +func (u *AUInt32) Swap(new uint32) uint32 { return atomic.SwapUint32(&u.value, new) } + +// AUInt32.Add +// Desc: +// Prms: +// Rets: +// +func (u *AUInt32) Add(dlt uint32) uint32 { return atomic.AddUint32(&u.value, dlt) } + +// AUInt32.Sub +// Desc: +// Prms: +// Rets: +// +func (u *AUInt32) Sub(dlt uint32) uint32 { return atomic.AddUint32(&u.value, ^uint32(dlt-1)) } + +// AUInt32.Inc +// Desc: +// Prms: +// Rets: +// +func (u *AUInt32) Inc() uint32 { return u.Add(1) } + +// AUInt32.Dec +// Desc: +// Prms: +// Rets: +// +func (u *AUInt32) Dec() uint32 { return u.Add(^uint32(0)) } + +// AUInt32.CAS +// Desc: +// Prms: +// Rets: +// +func (u *AUInt32) CAS(old, new uint32) bool { return atomic.CompareAndSwapUint32(&u.value, old, new) } + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/auint64.go b/core/syncs/auint64.go new file mode 100644 index 0000000..ae0127f --- /dev/null +++ b/core/syncs/auint64.go @@ -0,0 +1,121 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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 syncs + +import ( + "sync/atomic" +) + +type ( + + // AUInt64 + // Type: Struct + // Desc: + // + // + AUInt64 struct { + value uint64 + } +) + +// NewAUInt64 +// Desc: Función constructor para AUInt64 +// +// Prms: val, valor inicial +// Rets: Puntero al nuevo objeto creado. +// +func NewAUInt64(val uint64) *AUInt64 { return &AUInt64{value: val} } + +// AUInt64.Get +// Desc: +// Prms: +// Rets: +// +func (u *AUInt64) Get() uint64 { return atomic.LoadUint64(&u.value) } + +// AUInt64.Set +// Desc: +// Prms: +// Rets: +// +func (u *AUInt64) Set(val uint64) { atomic.StoreUint64(&u.value, val) } + +// AUInt64.Swap +// Desc: +// Prms: +// Rets: +// +func (u *AUInt64) Swap(new uint64) uint64 { return atomic.SwapUint64(&u.value, new) } + +// AUInt64.Add +// Desc: +// Prms: +// Rets: +// +func (u *AUInt64) Add(dlt uint64) uint64 { return atomic.AddUint64(&u.value, dlt) } + +// AUInt64.Sub +// Desc: +// Prms: +// Rets: +// +func (u *AUInt64) Sub(dlt uint64) uint64 { return atomic.AddUint64(&u.value, ^uint64(dlt-1)) } + +// AUInt64.Inc +// Desc: +// Prms: +// Rets: +// +func (u *AUInt64) Inc() uint64 { return u.Add(1) } + +// AUInt64.Dec +// Desc: +// Prms: +// Rets: +// +func (u *AUInt64) Dec() uint64 { return u.Add(^uint64(0)) } + +// AUInt64.CAS +// Desc: +// Prms: +// Rets: +// +func (u *AUInt64) CAS(old, new uint64) bool { return atomic.CompareAndSwapUint64(&u.value, old, new) } + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/b32_aint.go b/core/syncs/b32_aint.go new file mode 100644 index 0000000..4679ee0 --- /dev/null +++ b/core/syncs/b32_aint.go @@ -0,0 +1,64 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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. +// + +// +build 386 arm mips mipsle + +package syncs + +import ( + "sync/atomic" +) + +type AInt struct{ value int32 } + +func NewAInt(v int) *AInt { return &AInt{value: int32(v)} } + +func (u *AInt) Get() int { return int(atomic.LoadInt32(&u.value)) } +func (u *AInt) Set(v int) { atomic.StoreInt32(&u.value, int32(v)) } +func (u *AInt) Swap(new int) int { return int(atomic.SwapInt32(&u.value, int32(new))) } + +func (u *AInt) Add(dlt int) int { return int(atomic.AddInt32(&u.value, int32(dlt))) } +func (u *AInt) Sub(dlt int) int { return int(atomic.AddInt32(&u.value, -dlt)) } +func (u *AInt) Inc() int { return u.Add(1) } +func (u *AInt) Dec() int { return u.Add(-1) } + +func (u *AInt) CAS(old, new int) bool { + return atomic.CompareAndSwapInt32(&u.value, int32(old), int32(new)) +} + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/b32_uint.go b/core/syncs/b32_uint.go new file mode 100644 index 0000000..abec449 --- /dev/null +++ b/core/syncs/b32_uint.go @@ -0,0 +1,64 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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. +// + +// +build 386 arm mips mipsle + +package syncs + +import ( + "sync/atomic" +) + +type AUInt struct{ value uint32 } + +func NewAUint(v uint) *AUInt { return &AUInt{value: uint32(v)} } + +func (u *AUInt) Get() uint { return uint(atomic.LoadUint32(&u.value)) } +func (u *AUInt) Set(v uint) { atomic.StoreUint32(&u.value, uint32(v)) } +func (u *AUInt) Swap(new uint) uint { return uint(atomic.SwapUint32(&u.value, uint32(new))) } + +func (u *AUInt) Add(dlt uint) uint { return uint(atomic.AddUint32(&u.value, uint32(dlt))) } +func (u *AUInt) Sub(dlt uint) uint { return uint(atomic.AddUint32(&u.value, ^uint32(uint32(dlt)-1))) } +func (u *AUInt) Inc() uint { return u.Add(1) } +func (u *AUInt) Dec() uint { return u.Add(uint(^uint32(0))) } + +func (u *AUInt) CAS(old, new uint) bool { + return atomic.CompareAndSwapUint32(&u.value, uint32(old), uint32(new)) +} + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/b64_int.go b/core/syncs/b64_int.go new file mode 100644 index 0000000..2ac9bbc --- /dev/null +++ b/core/syncs/b64_int.go @@ -0,0 +1,124 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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. +// + +// +build amd64 arm64 ppc64 ppc64le mips64 mips64le s390x + +package syncs + +import ( + "sync/atomic" +) + +type ( + + // AInt + // Type: Struct + // Desc: + // + AInt struct { + value int64 + } +) + +// NewAInt +// Desc: Función constructor para AInt +// +// Prms: val, valor inicial +// Rets: Puntero al nuevo objeto creado. +// +func NewAInt(val int) *AInt { return &AInt{value: int64(val)} } + +// AInt.Get +// Desc: +// Prms: +// Rets: +// +func (u *AInt) Get() int { return int(atomic.LoadInt64(&u.value)) } + +// AInt.Set +// Desc: +// Prms: +// Rets: +// +func (u *AInt) Set(v int) { atomic.StoreInt64(&u.value, int64(v)) } + +// AInt.Swap +// Desc: +// Prms: +// Rets: +// +func (u *AInt) Swap(new int) int { return int(atomic.SwapInt64(&u.value, int64(new))) } + +// AInt.Add +// Desc: +// Prms: +// Rets: +// +func (u *AInt) Add(dlt int) int { return int(atomic.AddInt64(&u.value, int64(dlt))) } + +// AInt.Sub +// Desc: +// Prms: +// Rets: +// +func (u *AInt) Sub(dlt int) int { return int(atomic.AddInt64(&u.value, int64(-dlt))) } + +// AInt.Inc +// Desc: +// Prms: +// Rets: +// +func (u *AInt) Inc() int { return u.Add(1) } + +// AInt.Dec +// Desc: +// Prms: +// Rets: +// +func (u *AInt) Dec() int { return u.Add(-1) } + +// AInt.CAS +// Desc: +// Prms: +// Rets: +// +func (u *AInt) CAS(old, new int) bool { + return atomic.CompareAndSwapInt64(&u.value, int64(old), int64(new)) +} + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/b64_uint.go b/core/syncs/b64_uint.go new file mode 100644 index 0000000..b485c74 --- /dev/null +++ b/core/syncs/b64_uint.go @@ -0,0 +1,124 @@ +// +// Feb21 +// +// GO Active Thing +// Framework +// +// http://activething.com/dev/goat +// +// Dev : Juan V.Navarro +// Email: juanvnl@activething.com +// Date : 16/02/2021 +// +// Copyright 2021 the GOAT Authors +// +// 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. +// + +// +build amd64 arm64 ppc64 ppc64le mips64 mips64le s390x + +package syncs + +import ( + "sync/atomic" +) + +type ( + + // AUInt + // Type: Struct + // Desc: + // + AUInt struct { + value uint64 + } +) + +// NewAInt +// Desc: Función constructor para AUInt +// +// Prms: val, valor inicial +// Rets: Puntero al nuevo objeto creado. +// +func NewAUint(val int64) *AUInt { return &AUInt{value: uint64(val)} } + +// AUInt.Get +// Desc: +// Prms: +// Rets: +// +func (u *AUInt) Get() uint { return uint(atomic.LoadUint64(&u.value)) } + +// AUInt.Set +// Desc: +// Prms: +// Rets: +// +func (u *AUInt) Set(val uint) { atomic.StoreUint64(&u.value, uint64(val)) } + +// AUInt.Swap +// Desc: +// Prms: +// Rets: +// +func (u *AUInt) Swap(new uint) uint { return uint(atomic.SwapUint64(&u.value, uint64(new))) } + +// AUInt.Add +// Desc: +// Prms: +// Rets: +// +func (u *AUInt) Add(dlt uint) uint { return uint(atomic.AddUint64(&u.value, uint64(dlt))) } + +// AUInt.Sub +// Desc: +// Prms: +// Rets: +// +func (u *AUInt) Sub(dlt uint) uint { return uint(atomic.AddUint64(&u.value, ^uint64(dlt-1))) } + +// AUInt.Inc +// Desc: +// Prms: +// Rets: +// +func (u *AUInt) Inc() uint { return u.Add(1) } + +// AUInt.Dec +// Desc: +// Prms: +// Rets: +// +func (u *AUInt) Dec() uint { return uint(^uint64(0)) } + +// AUInt.CAS +// Desc: +// Prms: +// Rets: +// +func (u *AUInt) CAS(old, new uint) bool { + return atomic.CompareAndSwapUint64(&u.value, uint64(old), uint64(new)) +} + +/* + :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. + "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. + + SIDDHARTA + - HERMANN HESSE - + + ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +*/ diff --git a/core/syncs/nop_locker.go b/core/syncs/nop_locker.go index 7f1e368..a4f6fdb 100644 --- a/core/syncs/nop_locker.go +++ b/core/syncs/nop_locker.go @@ -26,20 +26,20 @@ package syncs type ( - LockerNop struct{} + NopLocker struct{} ) -func (_ LockerNop) Lock() {} +func (_ NopLocker) Lock() {} -func (_ LockerNop) Unlock() {} +func (_ NopLocker) Unlock() {} -func (_ LockerNop) RLock() {} +func (_ NopLocker) RLock() {} -func (_ LockerNop) RUnlock() {} +func (_ NopLocker) RUnlock() {} diff --git a/core/syncs/pool_ops.go b/core/syncs/pool_ops.go deleted file mode 100644 index 98b7d54..0000000 --- a/core/syncs/pool_ops.go +++ /dev/null @@ -1,69 +0,0 @@ -// ------------------------------------------------------------------------ -// Project atila -// Active Thing (activething.com) git.activething.com/go -// -// File name pool_ops.go -// Created by DEV -// Modified 17/01/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 syncs - -import ( - "opts" - "sync/atomic" -) - -func PoolWithNew[T any](nfn func() *T) opts.GOptionFnc[Pool[T]] { - return func(p *Pool[T]) { - p.createFn = nfn - } -} - - -func PoolWithCap[T any](cap int32) opts.GOptionFnc[Pool[T]] { - return func(p *Pool[T]) { - atomic.StoreInt32(&p.cap, cap) - } -} - - -func PoolWithLen[T any](len int32) opts.GOptionFnc[Pool[T]] { - return func(p *Pool[T]) { - if p.createFn == nil { - return - } - c := p.Cap() - if c != -1 && len > c { - len = c - } - for i := int32(0); i < len; i++ { - p.Put(p.createFn()) - } - } -} - - -func PoolWithSet[T any](els ...*T) opts.GOptionFnc[Pool[T]] { - return func(p *Pool[T]) { - for _, e := range els { - if e != nil { - p.Put(e) - } - } - } -} diff --git a/core/syncs/pool.go b/core/syncs/pools/g_pool.go similarity index 61% rename from core/syncs/pool.go rename to core/syncs/pools/g_pool.go index 67709cb..8140377 100644 --- a/core/syncs/pool.go +++ b/core/syncs/pools/g_pool.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package syncs +package pools import ( "opts" @@ -31,7 +31,7 @@ import ( type ( - Pool[T any] struct { + GPool[T any] struct { PoolStatsInfo inner sync.Pool @@ -43,19 +43,19 @@ type ( } ) -func NewPool[T any](ops ...opts.GOptionFnc[Pool[T]]) *Pool[T] { - return opts.GApply(&Pool[T]{}, ops...) } +func NewGPool[T any](ops ...opts.GOptionFnc[GPool[T]]) *GPool[T] { + return opts.GApply(&GPool[T]{}, ops...) } -func (p *Pool[T]) Len() int32 { +func (p *GPool[T]) Len() int32 { return atomic.LoadInt32(&p.len) } -func (p *Pool[T]) Cap() int32 { +func (p *GPool[T]) Cap() int32 { return atomic.LoadInt32(&p.cap) } -func (p *Pool[T]) Get() *T { +func (p *GPool[T]) Get() *T { o := p.inner.Get() if o != nil { p.AddAcquired() @@ -71,7 +71,7 @@ func (p *Pool[T]) Get() *T { } -func (p *Pool[T]) Put(obj *T) { +func (p *GPool[T]) Put(obj *T) { if obj == nil { return } @@ -84,8 +84,51 @@ func (p *Pool[T]) Put(obj *T) { } -func (p *Pool[T]) Empty() { +func (p *GPool[T]) Empty() { for p.Len() > 0 { _ = p.Get() } } + + + + +func WithNew[T any](nfn func() *T) opts.GOptionFnc[GPool[T]] { + return func(p *GPool[T]) { + p.createFn = nfn + } +} + + +func WithCap[T any](cap int32) opts.GOptionFnc[GPool[T]] { + return func(p *GPool[T]) { + atomic.StoreInt32(&p.cap, cap) + } +} + + +func WithLen[T any](len int32) opts.GOptionFnc[GPool[T]] { + return func(p *GPool[T]) { + if p.createFn == nil { + return + } + c := p.Cap() + if c != -1 && len > c { + len = c + } + for i := int32(0); i < len; i++ { + p.Put(p.createFn()) + } + } +} + + +func WithSet[T any](els ...*T) opts.GOptionFnc[GPool[T]] { + return func(p *GPool[T]) { + for _, e := range els { + if e != nil { + p.Put(e) + } + } + } +} diff --git a/core/syncs/pool_call_sizes.go b/core/syncs/pools/pool_call_sizes.go similarity index 98% rename from core/syncs/pool_call_sizes.go rename to core/syncs/pools/pool_call_sizes.go index 2588808..5586edf 100644 --- a/core/syncs/pool_call_sizes.go +++ b/core/syncs/pools/pool_call_sizes.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package syncs +package pools type ( PoolCallSize struct { diff --git a/core/syncs/pool_stats.go b/core/syncs/pools/pool_stats.go similarity index 98% rename from core/syncs/pool_stats.go rename to core/syncs/pools/pool_stats.go index b49d851..92c5cdb 100644 --- a/core/syncs/pool_stats.go +++ b/core/syncs/pools/pool_stats.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package syncs +package pools diff --git a/core/syncs/pool_stats_info.go b/core/syncs/pools/pool_stats_info.go similarity index 99% rename from core/syncs/pool_stats_info.go rename to core/syncs/pools/pool_stats_info.go index 8c9f9c1..444a836 100644 --- a/core/syncs/pool_stats_info.go +++ b/core/syncs/pools/pool_stats_info.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package syncs +package pools import "sync/atomic" diff --git a/core/syncs/queue/g_queue.go b/core/syncs/queue/g_queue.go new file mode 100644 index 0000000..e50108d --- /dev/null +++ b/core/syncs/queue/g_queue.go @@ -0,0 +1,85 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name g_queue.go +// Created by DEV +// Modified 24/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 queue + +import ( + "sync" + "syncs" +) + +type ( + + GQueue [T any]struct { + locker syncs.LockerRW + elems []T + } + +) + + +func NewGQueue [T any](safe bool) *GQueue[T] { + var lc syncs.LockerRW + if safe { + lc = &sync.RWMutex{} + } + return &GQueue[T]{ locker : lc } +} + + +func (q *GQueue[T]) Len () (l int) { + q.locker.RLock() + l = len(q.elems) + q.locker.RUnlock() + return +} + + +func (q *GQueue[T]) Push(ele T) { + q.locker.Lock() + q.elems = append(q.elems,ele) + q.locker.Unlock() +} + + +func (q *GQueue[T]) Pop() (e T) { + q.locker.Lock() + if q.Len() > 0 { + e = q.elems[0] + q.elems = q.elems[1:] + } + q.locker.Unlock() + return +} + + +func (q *GQueue[T]) Clear (onClearFnc func(ele T)) { + q.locker.Lock() + if onClearFnc != nil { + for _,e := range q.elems { + onClearFnc(e) + } + } + q.elems = q.elems[:0] + q.locker.Unlock() +} diff --git a/core/syncs/works/pool.go b/core/syncs/works/pool.go index 75f5a77..2ff0429 100644 --- a/core/syncs/works/pool.go +++ b/core/syncs/works/pool.go @@ -28,7 +28,7 @@ import ( "runtime" "sync" "sync/atomic" - "syncs" + "syncs/pools" "time" ) @@ -36,7 +36,7 @@ import ( type ( Pool struct { - stats *syncs.PoolStatsInfo + stats *pools.PoolStatsInfo pool sync.Pool mux sync.Mutex @@ -62,7 +62,7 @@ func NewPool(options ...PoolFnc) *Pool { c = 0 } wp := &Pool{ - stats : syncs.NewPoolStatsInfo(), + stats : pools.NewPoolStatsInfo(), maxIdle: int64(maxIdle), cap : c, max : maxWorkers, @@ -82,7 +82,7 @@ func (p *Pool) newWorker () any { jobCh: make(chan func(), atomic.LoadInt32(&p.cap)) }} -func (p *Pool) Stats () syncs.PoolStats { +func (p *Pool) Stats () pools.PoolStats { return p.stats } diff --git a/go.work b/go.work index b2bde8b..4a2ebe3 100644 --- a/go.work +++ b/go.work @@ -3,7 +3,7 @@ go 1.22 use ( ./core/errs - ./core/rsts + ./core/results ./core/codecs ./core/crypts ./core/vals @@ -17,8 +17,8 @@ use ( ./core/ctxs ./core/atypes ./core/mems - ./packs - ./logs + ./proteus + ./hecate ./app ) \ No newline at end of file diff --git a/logs/active.go b/hecate/active.go similarity index 63% rename from logs/active.go rename to hecate/active.go index e08b21f..48173dd 100644 --- a/logs/active.go +++ b/hecate/active.go @@ -23,6 +23,13 @@ package logs +import ( + "bins/tokens" + "mems" + "syncs" + "syncs/pools" + "time" +) const ( @@ -34,21 +41,60 @@ const ( LevelNameFatal string = "FATAL" levelNameSep string = "|" + + + + filterLevelName string = "level" + filterScopeName string = "scope" +) + +const ( + msgLogLogErr = "Error logging core logger" + msgLogStartErr = "Error starting core logger" + msgLogStopErr = "Error stopping core logger" + msgLogFlushErr = "Error flushing core logger" ) + var ( G = struct { + ErrInvalidLevel ErrLogs ErrDuplicatedScope ErrLogs ErrDuplicatedLogger ErrLogs ErrInvalidScope ErrLogs + ErrInvalidScopeMode ErrLogs ErrNotExistsLogger ErrLogs + + ScopeSep byte + }{ + ErrInvalidLevel : ErrLogs{ "invalid-level"}, ErrDuplicatedScope : ErrLogs{"duplicated-scope" }, ErrDuplicatedLogger : ErrLogs{"duplicated-logger"}, ErrInvalidScope : ErrLogs{"invalid-scope"}, + ErrInvalidScopeMode : ErrLogs{ "invalid-scope-mode"}, ErrNotExistsLogger : ErrLogs{"not-exists-logger"}, + + ScopeSep : '.', + + } + + g = struct { + idGen syncs.AUInt64 + entryPool pools.GPool[Entry] + bufferPool mems.Pool + tokenizer tokens.ATokenizer + + scopeSepStr string + }{ + idGen : *syncs.NewAUInt64(uint64(time.Now().Unix())), + bufferPool: *mems.NewPool(), + tokenizer : *tokens.NewATokenizer(), + entryPool : *pools.NewGPool[Entry](pools.WithNew(newEntry)), + + scopeSepStr : ".", } ) diff --git a/hecate/aggregator.go b/hecate/aggregator.go new file mode 100644 index 0000000..198e19f --- /dev/null +++ b/hecate/aggregator.go @@ -0,0 +1,53 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name aggregator.go +// Created by DEV +// Modified 25/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 logs + + +type ( + + Aggregators []EntryFnc + +) + + + +func (a Aggregators) Apply (entry *Entry) *Entry{ + for _,f := range a { + f(entry) + } + return entry +} + + +func (a Aggregators) Append (entryFn ... EntryFnc) Aggregators { + return append(a,entryFn...) } + + + + + + + + + diff --git a/hecate/alogger.go b/hecate/alogger.go new file mode 100644 index 0000000..3e5feaf --- /dev/null +++ b/hecate/alogger.go @@ -0,0 +1,90 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name hecate.go +// Created by DEV +// Modified 25/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 logs + +import ( + "errs" + "syncs/queue" +) + +type ( + + ALogger struct { + loggerLevel + Aggregators + Filters + + scopes Scopes + + queue queue.GQueue[*Entry] + + state State + count int + + logErrors bool + errors errs.ErrorList + + + } + + + ManagerFnc func(manager *ALogger) +) + + +func NewALogger(name string, level Level, options ...ManagerFnc) *ALogger { + m := &ALogger{ + loggerLevel : *newLoggerLevel(name,level), + Filters : *NewFilters(), + + state : StateCreated, + logErrors : true, + } + m.logFn = m.log + for o := range options { + o(m) + } + return m +} + + +func (l *ALogger) Start (all bool) error { + l.mux.Lock() + if l.state == StateStarted { + l.mux.Unlock() + return nil + } + + l.errors = l.errors[:0] + l.state = StateStarted + + if !all { + l.mux.Unlock() + return nil + } + + for _,cl := range l.cores { + + } +} diff --git a/hecate/appender.go b/hecate/appender.go new file mode 100644 index 0000000..959f903 --- /dev/null +++ b/hecate/appender.go @@ -0,0 +1,40 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name appender.go +// Created by DEV +// Modified 24/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 logs + + +type ( + + Appender interface { + + Append (entry *Entry) error + } + + AppendFnc func (entry *Entry) error +) + + +func (f AppendFnc) Append (entry *Entry) error { + return f(entry) } + diff --git a/hecate/entry.go b/hecate/entry.go new file mode 100644 index 0000000..ad61773 --- /dev/null +++ b/hecate/entry.go @@ -0,0 +1,136 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name entry.go +// Created by DEV +// Modified 23/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 logs + +import ( + "atypes/slices" + "time" +) + +type ( + + + Entry struct { + Logger Logger + + Id uint64 + Scope string + Scopes [][]byte + Level Level + + Message string + Date time.Time + + Error error + + Data any + + excludes slices.Strings + } + + + + EntryFnc func (entry *Entry) +) + + + + + + +func AcquireEntry (logger Logger, level Level, message string, err error, options ...EntryFnc) *Entry { + return g.entryPool.Get().init(logger,level,message,err,options...) } + +func ReleaseEntry (entry *Entry) { + g.entryPool.Put(entry.reset()) } + + + +func NewEntry (logger Logger, level Level, message string, err error, options ...EntryFnc) *Entry { + return newEntry().init(logger,level,message,err,options...) } + +func newEntry () *Entry { + return &Entry{} } + +func (e *Entry) init (logger Logger, level Level, message string, err error, options ...EntryFnc) *Entry { + e.Id = g.idGen.Inc() + e.Logger = logger + e.Level = level + e.Error = err + e.Message= message + e.Date = time.Now() + for _,o := range options { + o(e) + } + return e +} + + +func (e *Entry) reset () *Entry { + if e == nil { + return nil + } + e.Logger = nil + e.excludes = e.excludes.Reset() + for _,s := range e.Scopes { + s = s[:0] + } + e.Scopes = e.Scopes[:0] + e.Error = nil + e.Data = nil + e.Message= "" + + return e +} + + +func (e *Entry) IsExcluded (value string) bool { + return e.excludes.Has(value) } + + +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 0 { + e.excludes = e.excludes.Append(ex) + } + } + } +} \ No newline at end of file diff --git a/hecate/entry_logger.go b/hecate/entry_logger.go new file mode 100644 index 0000000..6343691 --- /dev/null +++ b/hecate/entry_logger.go @@ -0,0 +1,41 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name entry_logger.go +// Created by DEV +// Modified 24/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 logs + + +type ( + + EntryLogger interface { + + Log (entry *Entry) error + } + + + LogEntryFnc func(entry *Entry) error +) + + +func (f LogEntryFnc) Log(entry *Entry) error { + return f(entry) } + diff --git a/logs/err_logs.go b/hecate/err_logs.go similarity index 100% rename from logs/err_logs.go rename to hecate/err_logs.go diff --git a/hecate/filter.go b/hecate/filter.go new file mode 100644 index 0000000..f28f073 --- /dev/null +++ b/hecate/filter.go @@ -0,0 +1,105 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name entry_filter.go +// Created by DEV +// Modified 24/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 logs + +import ( + "bins/tokens" + "strings" +) + +type ( + + Filter struct { + name string + active bool + filterFnc FilterFnc + } + + + FilterFnc func (entry *Entry) bool + + +) + +func NewFilter(name string, fnc FilterFnc) *Filter { + if fnc == nil { + fnc = NopFilterTrue + } + return &Filter{ + name : name, + active : true, + filterFnc : fnc, + } +} + + +func NewFilterLevel (name string, level Level) *Filter { + if len(name) == 0 { + name = filterLevelName + } + l := level + return &Filter{ + name : name, + active : true, + filterFnc: func(e *Entry) bool { + return l.Has(e.Level) + }, + } +} + +func NewFilterScope (name string, topic string) *Filter { + if len(name) == 0 { + name = filterScopeName + } + tp := *g.tokenizer.NewTopic([]byte(strings.ToLower(topic)),tokens.TokenKindAll) + return &Filter{ + name : name, + active : true, + filterFnc: func(e *Entry) bool { + return tp.Match(e.Scopes) + }, + } +} + + +func (f *Filter) Name () string { + return f.name } + +func (f *Filter) IsActive () bool { + return f.active } + +func (f *Filter) SetActive (enable bool) { + f.active = enable } + +func (f *Filter) Filter (entry *Entry) bool { + return f.filterFnc(entry) } + + + +func NopFilterTrue (_ *Entry) bool { + return true } + + +func NopFilterFalse(_ *Entry) bool { + return false } \ No newline at end of file diff --git a/hecate/filters.go b/hecate/filters.go new file mode 100644 index 0000000..52a65f2 --- /dev/null +++ b/hecate/filters.go @@ -0,0 +1,116 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name filters.go +// Created by DEV +// Modified 24/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 logs + + +type ( + + Filters struct { + allows []*Filter + denies []*Filter + } + + + FiltersFnc func(f *Filters) +) + + +func NewFilters (options ...FiltersFnc) *Filters { + f := &Filters { + } + for _,o := range options { + o(f) + } + return f +} + +func (f *Filters) AddFilterAllowed(filter *Filter) { + f.add(filter,&f.allows) } + +func (f *Filters) AddFilterDenied (filter *Filter) { + f.add(filter,&f.denies) } + +func (f *Filters) DelFilterAllowed(name string) { + f.del(name,&f.allows) } + +func (f *Filters) DelFilterDenied (name string) { + f.del(name,&f.denies) } + + + +func (f *Filters) Filter (entry *Entry) bool { + + if len(f.allows) > 0 { + p := false + for _,fi := range f.allows { + if fi.IsActive() { + if p = fi.Filter(entry); p { + break + } + } + } + if !p { + return false + } + } + + for _,fi := range f.denies { + if fi.IsActive() { + if fi.Filter(entry) { + return false + } + } + } + + return true +} + + + +func (f *Filters) add (ft *Filter, ls *[]*Filter) { + if p := filterPos(*ls, ft.name); p != -1 { + (*ls)[p]= ft + return + } + *ls = append(*ls, ft) +} + +func (f *Filters) del (name string, ls *[]*Filter) { + if p := filterPos(*ls,name); p != -1 { + *ls = append((*ls)[:p],(*ls)[p+1:]...) + } +} + + + + + +func filterPos (list []*Filter, name string) int { + for i,f := range list { + if f.name == name { + return i + } + } + return -1 +} \ No newline at end of file diff --git a/hecate/go.mod b/hecate/go.mod new file mode 100644 index 0000000..36a8ebe --- /dev/null +++ b/hecate/go.mod @@ -0,0 +1,3 @@ +module hecate + +go 1.22 diff --git a/logs/level.go b/hecate/level.go similarity index 96% rename from logs/level.go rename to hecate/level.go index f557612..1e96f55 100644 --- a/logs/level.go +++ b/hecate/level.go @@ -28,20 +28,26 @@ import ( "strings" ) + const( levelsCount int = 6 +) + +const( - LevelNone Level = 0 - LevelData Level = 1 << iota + LevelData Level = 1 << iota LevelDebug LevelInfo LevelWarn LevelError LevelFatal + LevelNone Level = 0 + LevelAll Level = LevelData|LevelDebug|LevelInfo|LevelWarn|LevelError|LevelFatal + ) @@ -109,7 +115,8 @@ func (lv Level) HasFatal() bool { return lv&LevelFatal!=0 } - +func (lv Level) isValid () bool { + return lv <= LevelAll } diff --git a/logs/entry.go b/hecate/log.go similarity index 88% rename from logs/entry.go rename to hecate/log.go index 6988990..1ede6c3 100644 --- a/logs/entry.go +++ b/hecate/log.go @@ -2,9 +2,9 @@ // Project active2 // Active Thing (activething.com) git.activething.com/go // -// File name entry.go +// File name log.go // Created by DEV -// Modified 23/04/2024 +// Modified 24/04/2024 // // Copyright 2024 activething.com // ------------------------------------------------------------------------ @@ -27,15 +27,7 @@ package logs type ( - - Entry struct { - Logger Logger - - - } - - - EntryFnc func (entry *Entry) + LogFnc func (level Level, message string, err error, options ...EntryFnc) ) diff --git a/logs/loggable.go b/hecate/loggable.go similarity index 100% rename from logs/loggable.go rename to hecate/loggable.go diff --git a/logs/logger.go b/hecate/logger.go similarity index 100% rename from logs/logger.go rename to hecate/logger.go diff --git a/hecate/logger_core.go b/hecate/logger_core.go new file mode 100644 index 0000000..8a5b85f --- /dev/null +++ b/hecate/logger_core.go @@ -0,0 +1,52 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name logger_core.go +// Created by DEV +// Modified 25/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 logs + +import "errs" + +type ( + + LoggerCore struct { + loggerLevel + Filters + Aggregators + Appender + + state State + count int + + errors errs.ErrorList + + } + + + LoggerCoreFnc func(l *LoggerCore) +) + + + + +func NewLoggerCore (name string, level Level, options ...LoggerCoreFnc) *LoggerCore { + +} \ No newline at end of file diff --git a/hecate/logger_level.go b/hecate/logger_level.go new file mode 100644 index 0000000..db44d80 --- /dev/null +++ b/hecate/logger_level.go @@ -0,0 +1,93 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name logger_level.go +// Created by DEV +// Modified 24/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 logs + +import "sync" + +type ( + + + loggerLevel struct { + mux sync.RWMutex + name string + level Level + logFn LogFnc + } + +) + + +func newLoggerLevel (name string, level Level) *loggerLevel { + return &loggerLevel{ + name : name, + level: level } } + + +func (l *loggerLevel) Name () string { + return l.name } + +func (l *loggerLevel) Level() (lv Level) { + l.mux.RLock() + lv = l.level + l.mux.RUnlock() + return +} + +func (l *loggerLevel) SetLevel (level Level) { + l.mux.Lock() + l.level = level + l.mux.Unlock() +} + + + +func (l *loggerLevel) Fatal (msg string, err error, ops ...EntryFnc){ + l.logFn(LevelFatal,msg,err,ops ...) } + + +func (l *loggerLevel) Error (msg string, err error, ops ...EntryFnc){ + l.logFn(LevelError,msg,err,ops ...) } + + +func (l *loggerLevel) Warn (msg string, ops ...EntryFnc){ + l.logFn(LevelWarn,msg,nil,ops ...) } + + +func (l *loggerLevel) Info (msg string, ops ...EntryFnc){ + l.logFn(LevelInfo,msg,nil,ops...) } + + +func (l *loggerLevel) Debug (msg string, ops ...EntryFnc){ + l.logFn(LevelDebug,msg,nil,ops...) } + + +func (l *loggerLevel) Data (msg string, data any, ops ...EntryFnc){ + l.logFn(LevelData,msg,nil,func (e *Entry) { + e.Data = data + for _,o := range ops { + o(e) + } + }) } + + diff --git a/hecate/scope.go b/hecate/scope.go new file mode 100644 index 0000000..6fedbe0 --- /dev/null +++ b/hecate/scope.go @@ -0,0 +1,192 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name scope.go +// Created by DEV +// Modified 24/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 logs + +import ( + "fmt" + "strings" +) + +type ( + + + Scope struct { + loggerLevel + Aggregators + + path string + nodes [][]byte + + mode ScopeMode + parent Loggable + scopes Scopes + } + + ScopeFnc func (s *Scope) + +) + + +func newScope(name string, level Level, parent Loggable, path string, nodes [][]byte, options []ScopeFnc) *Scope { + if path != "" { + path = fmt.Sprintf("%s%c%s",path,G.ScopeSep,name) + } else { + path = name + } + sc := &Scope { + loggerLevel: *newLoggerLevel(name,level), + parent: parent, + nodes : append(nodes,[]byte(name)), + path : path, + } + sc.logFn = sc.log + for _,o := range options { + o(sc) + } + return sc +} + + +func (s *Scope) Nodes() [][]byte { + return s.nodes } + +func (s *Scope) Path () string { + return s.path } + +func (s *Scope) Mode () (m ScopeMode) { + s.mux.RLock() + m = s.mode + s.mux.RUnlock() + return +} + +func (s *Scope) SetMode (mode ScopeMode) { + if !mode.isValid() { + panic(G.ErrInvalidScopeMode) + } + s.mux.Lock() + s.mode = mode + s.mux.Unlock() +} + +func (s *Scope) GetScope (name string) *Scope { + return s.getScope(strings.Split(strings.ToLower(name),g.scopeSepStr)) } + +func (s *Scope) getScope (nodes []string)( sc *Scope) { + s.mux.RLock() + if sc = s.scopes.getScope(nodes[0]); sc != nil { + if len(nodes) > 1 { + sc = sc.getScope(nodes[:1]) + } + } + s.mux.RUnlock() + return +} + + +func (s *Scope) NewScope (path string, options ...ScopeFnc) (*Scope,error) { + return s.newScope(strings.Split(strings.ToLower(path),g.scopeSepStr),options) } + +func (s *Scope) newScope (path []string, options []ScopeFnc) (sc *Scope, er error) { + s.mux.Lock() + if sc = s.scopes.getScope(path[0]); sc == nil { + sc = newScope(path[0], s.level, s, s.path, s.nodes,options) + s.scopes = append(s.scopes, sc) + if len(path) == 1 { + s.mux.Unlock() + return + } + } else if len(path) == 1 { + s.mux.Unlock() + return nil,G.ErrDuplicatedScope + } + sc,er = sc.newScope(path[1:],options) + s.mux.Unlock() + return +} + + + + +func (s *Scope) Log(ent *Entry) error { + s.mux.Lock() + if s.mode & ScopeFilter != 0 && !s.level.Has(ent.Level) { + s.mux.Unlock() + return nil + } + if s.mode.IsCascade() { + s.Apply(ent) + } + s.mux.Unlock() + return s.parent.Log(ent) +} + + +func (s *Scope) log(lvl Level, msg string, err error,ops ...EntryFnc){ + s.mux.Lock() + if !s.level.Has(lvl) { + s.mux.Unlock() + return + } + en := s.Apply(AcquireEntry(nil,lvl,msg,err,ops...)) + en.Scope = s.path + en.Scopes= s.nodes + s.mux.Unlock() + + s.parent.Log(en) + ReleaseEntry(en) + +} + + +func ScopeWithMode (mode ScopeMode) ScopeFnc { + return func(s *Scope) { + if !mode.isValid() { + panic(G.ErrInvalidScopeMode) + } + if mode == ScopeDirect { + s.mode = ScopeDirect + return + } + s.mode |= mode + } +} + + +func ScopeWithLevel (level Level) ScopeFnc { + return func(s *Scope) { + if !level.isValid() { + panic(G.ErrInvalidLevel) + } + s.level = level + } +} + +func ScopeWithAggregator (aggregator ...EntryFnc) ScopeFnc { + return func(s *Scope) { + for _,a := range aggregator { + s.Aggregators = s.Aggregators.Append(a) + } + } +} \ No newline at end of file diff --git a/hecate/scope_mode.go b/hecate/scope_mode.go new file mode 100644 index 0000000..9b28dce --- /dev/null +++ b/hecate/scope_mode.go @@ -0,0 +1,56 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name scope.go +// Created by DEV +// Modified 24/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 logs + + +const ( + + ScopeCascade ScopeMode = 1 << iota + ScopeFilter + + ScopeDirect = 0 + +) + +type ( + + ScopeMode uint8 +) + + +func (m ScopeMode) isValid () bool { + return m <= ScopeFilter } + + +func (m ScopeMode) IsDirect() bool { + return m == ScopeDirect } + +func (m ScopeMode) IsCascade() bool { + return m & ScopeCascade != 0 } + +func (m ScopeMode) IsFilter () bool { + return m & ScopeFilter != 0 } + + + diff --git a/hecate/scopes.go b/hecate/scopes.go new file mode 100644 index 0000000..c0a341d --- /dev/null +++ b/hecate/scopes.go @@ -0,0 +1,63 @@ +// ------------------------------------------------------------------------ +// Project active2 +// Active Thing (activething.com) git.activething.com/go +// +// File name scopes.go +// Created by DEV +// Modified 25/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 logs + + + +type ( + + Scopes []*Scope +) + + +func (s Scopes) getScope (name string) *Scope { + if ps := s.find(name); ps != -1 { + return s[ps] + } + return nil +} + + +func (s Scopes) find (name string) int { + for i,e := range s { + if e.name == name { + return i + } + } + return -1 +} + + +func (s Scopes) walk(walkfn func(sc *Scope) bool) bool { + ex := true + for i:=0; i 0 { - p.state.WriteByte(',') - } - caller() - if p.state != nil { - p.state.Inc() - } -} - - diff --git a/packs/active.go b/proteus/active.go similarity index 96% rename from packs/active.go rename to proteus/active.go index d362850..ebc85fc 100644 --- a/packs/active.go +++ b/proteus/active.go @@ -21,11 +21,11 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus import ( "errs" - "syncs" + "syncs/pools" ) const( @@ -69,7 +69,7 @@ var ( g = struct { poolsSem uint32 - statePool *syncs.Pool[State] + statePool *pools.GPool[State] } {} ) diff --git a/packs/builder.go b/proteus/builder.go similarity index 98% rename from packs/builder.go rename to proteus/builder.go index c5e899b..bf4fbcd 100644 --- a/packs/builder.go +++ b/proteus/builder.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus diff --git a/packs/err_packs.go b/proteus/err_packs.go similarity index 98% rename from packs/err_packs.go rename to proteus/err_packs.go index 6d9fc1d..989f65b 100644 --- a/packs/err_packs.go +++ b/proteus/err_packs.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus import "errs" diff --git a/packs/flags.go b/proteus/flags.go similarity index 99% rename from packs/flags.go rename to proteus/flags.go index 11799e1..f06318d 100644 --- a/packs/flags.go +++ b/proteus/flags.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus import ( "bits" diff --git a/packs/fold.go b/proteus/fold.go similarity index 99% rename from packs/fold.go rename to proteus/fold.go index a270311..f609067 100644 --- a/packs/fold.go +++ b/proteus/fold.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus import ( "bins/chars" diff --git a/proteus/go.mod b/proteus/go.mod new file mode 100644 index 0000000..535ac7e --- /dev/null +++ b/proteus/go.mod @@ -0,0 +1,7 @@ +module proteus + + +go 1.22 + + + diff --git a/packs/list_pack_builder.go b/proteus/list_pack_builder.go similarity index 99% rename from packs/list_pack_builder.go rename to proteus/list_pack_builder.go index a2dc618..eaac17e 100644 --- a/packs/list_pack_builder.go +++ b/proteus/list_pack_builder.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus import "time" diff --git a/packs/map_pack_builder.go b/proteus/map_pack_builder.go similarity index 99% rename from packs/map_pack_builder.go rename to proteus/map_pack_builder.go index b30ccd3..32372d6 100644 --- a/packs/map_pack_builder.go +++ b/proteus/map_pack_builder.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus import "time" diff --git a/packs/object_pack_builder.go b/proteus/object_pack_builder.go similarity index 99% rename from packs/object_pack_builder.go rename to proteus/object_pack_builder.go index 1ac74c0..50dadbc 100644 --- a/packs/object_pack_builder.go +++ b/proteus/object_pack_builder.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus import "time" diff --git a/packs/packer.go b/proteus/packer.go similarity index 98% rename from packs/packer.go rename to proteus/packer.go index c1930f1..d4fb3e4 100644 --- a/packs/packer.go +++ b/proteus/packer.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus type ( diff --git a/packs/pjson/active.go b/proteus/pjson/active.go similarity index 94% rename from packs/pjson/active.go rename to proteus/pjson/active.go index 7036bb6..a7a60fa 100644 --- a/packs/pjson/active.go +++ b/proteus/pjson/active.go @@ -28,7 +28,6 @@ import ( "encoding/json" "packs" "reflect" - "rsts" "sync" ) @@ -39,7 +38,7 @@ const ( maxCyclesAfter = 100 - defaultFlags = packs.Flags(0) + defaultFlags = proteus.Flags(0) ) @@ -59,7 +58,7 @@ var ( jsonMarshalerType: reflect.TypeOf((*json.Marshaler)(nil)).Elem(), textMarshalerType: reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem(), - packMarshalerType: reflect.TypeOf((*packs.Packer)(nil)).Elem(), + packMarshalerType: reflect.TypeOf((*proteus.Packer)(nil)).Elem(), } ) diff --git a/packs/pjson/json_packer.go b/proteus/pjson/json_packer.go similarity index 61% rename from packs/pjson/json_packer.go rename to proteus/pjson/json_packer.go index b3515fa..1760615 100644 --- a/packs/pjson/json_packer.go +++ b/proteus/pjson/json_packer.go @@ -38,7 +38,7 @@ type ( JSONPacker struct { - state *packs.State + state *proteus.State dirty bool } @@ -49,7 +49,7 @@ type ( func NewJSONPacker(options ...JSONPackerFnc) *JSONPacker { pk := &JSONPacker{ - state : packs.NewState(), + state : proteus.NewState(), } for _,o := range options { o(pk) @@ -59,12 +59,12 @@ func NewJSONPacker(options ...JSONPackerFnc) *JSONPacker { -func (p *JSONPacker) Pack (value any, flags packs.Flags) { +func (p *JSONPacker) Pack (value any, flags proteus.Flags) { if p.state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(p.state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(p.state.Error)) } if p.dirty { - panic(packs.G.ErrInvalidState) + panic(proteus.G.ErrInvalidState) } p.dirty = true p.PackAny(value,flags) @@ -86,14 +86,14 @@ func (p *JSONPacker) Reset () { func (p *JSONPacker) Release () { p.dirty = false - packs.ReleaseState(p.state) + proteus.ReleaseState(p.state) } -func (p *JSONPacker) PackAny (value any, flags packs.Flags) { +func (p *JSONPacker) PackAny (value any, flags proteus.Flags) { if p.state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(p.state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(p.state.Error)) } if value == nil { p.state.W(cjson.G.NullValue) @@ -101,7 +101,7 @@ func (p *JSONPacker) PackAny (value any, flags packs.Flags) { } switch v := value.(type) { - case packs.Builder: + case proteus.Builder: p.state.SetError(v.Build(p)) case json.Marshaler: @@ -166,45 +166,45 @@ func (p *JSONPacker) PackAny (value any, flags packs.Flags) { -func (p *JSONPacker) PackRaw (value []byte, flags packs.Flags) { packRaw(p.state,value,flags) } +func (p *JSONPacker) PackRaw (value []byte, flags proteus.Flags) { packRaw(p.state,value,flags) } -func (p *JSONPacker) PackBinary (value []byte, flags packs.Flags) { packBinary(p.state,value,flags) } -func (p *JSONPacker) PackString (value string, flags packs.Flags) { packString (p.state,value,flags) } +func (p *JSONPacker) PackBinary (value []byte, flags proteus.Flags) { packBinary(p.state,value,flags) } +func (p *JSONPacker) PackString (value string, flags proteus.Flags) { packString (p.state,value,flags) } -func (p *JSONPacker) PackBool (value bool, flags packs.Flags) { packBool(p.state,value,flags) } +func (p *JSONPacker) PackBool (value bool, flags proteus.Flags) { packBool(p.state,value,flags) } -func (p *JSONPacker) PackInt8 (value int8 , flags packs.Flags) { packInt(p.state,int64(value),flags) } -func (p *JSONPacker) PackInt16 (value int16, flags packs.Flags) { packInt(p.state,int64(value),flags) } -func (p *JSONPacker) PackInt32 (value int32, flags packs.Flags) { packInt(p.state,int64(value),flags) } -func (p *JSONPacker) PackInt64 (value int64, flags packs.Flags) { packInt(p.state,value,flags)} +func (p *JSONPacker) PackInt8 (value int8 , flags proteus.Flags) { packInt(p.state,int64(value),flags) } +func (p *JSONPacker) PackInt16 (value int16, flags proteus.Flags) { packInt(p.state,int64(value),flags) } +func (p *JSONPacker) PackInt32 (value int32, flags proteus.Flags) { packInt(p.state,int64(value),flags) } +func (p *JSONPacker) PackInt64 (value int64, flags proteus.Flags) { packInt(p.state,value,flags)} -func (p *JSONPacker) PackUInt8 (value uint8 , flags packs.Flags) { packUInt(p.state,uint64(value),flags) } -func (p *JSONPacker) PackUInt16 (value uint16, flags packs.Flags) { packUInt(p.state,uint64(value),flags) } -func (p *JSONPacker) PackUInt32 (value uint32, flags packs.Flags) { packUInt(p.state,uint64(value),flags) } -func (p *JSONPacker) PackUInt64 (value uint64, flags packs.Flags) { packUInt(p.state, value,flags) } +func (p *JSONPacker) PackUInt8 (value uint8 , flags proteus.Flags) { packUInt(p.state,uint64(value),flags) } +func (p *JSONPacker) PackUInt16 (value uint16, flags proteus.Flags) { packUInt(p.state,uint64(value),flags) } +func (p *JSONPacker) PackUInt32 (value uint32, flags proteus.Flags) { packUInt(p.state,uint64(value),flags) } +func (p *JSONPacker) PackUInt64 (value uint64, flags proteus.Flags) { packUInt(p.state, value,flags) } -func (p *JSONPacker) PackFloat32 (value float32, flags packs.Flags) { packFloatString(p.state, float64(value), flags, 32) } -func (p *JSONPacker) PackFloat64 (value float64, flags packs.Flags) { packFloatString(p.state, value, flags, 64) } +func (p *JSONPacker) PackFloat32 (value float32, flags proteus.Flags) { packFloatString(p.state, float64(value), flags, 32) } +func (p *JSONPacker) PackFloat64 (value float64, flags proteus.Flags) { packFloatString(p.state, value, flags, 64) } -func (p *JSONPacker) PackDate (value time.Time, flags packs.Flags) { packDate(p.state,value,flags) } +func (p *JSONPacker) PackDate (value time.Time, flags proteus.Flags) { packDate(p.state,value,flags) } -func (p *JSONPacker) PackList (builder func(packs.ListPackBuilder, packs.Flags), flags packs.Flags) { - p.packCompound('[',']',builder==nil,func(pk *JSONPacker, fl packs.Flags){ builder(pk,fl) },flags) +func (p *JSONPacker) PackList (builder func(proteus.ListPackBuilder, proteus.Flags), flags proteus.Flags) { + p.packCompound('[',']',builder==nil,func(pk *JSONPacker, fl proteus.Flags){ builder(pk,fl) },flags) } -func (p *JSONPacker) PackMap (builder func(packs.MapPackBuilder, packs.Flags), flags packs.Flags) { - p.packCompound('{','}',builder==nil,func(pk *JSONPacker, fl packs.Flags){ builder(pk,fl) },flags) +func (p *JSONPacker) PackMap (builder func(proteus.MapPackBuilder, proteus.Flags), flags proteus.Flags) { + p.packCompound('{','}',builder==nil,func(pk *JSONPacker, fl proteus.Flags){ builder(pk,fl) },flags) } -func (p *JSONPacker) PackObject(builder func(packs.ObjectPackBuilder, packs.Flags), flags packs.Flags) { - p.packCompound('{','}',builder==nil,func(pk *JSONPacker, fl packs.Flags){ builder(pk,fl) },flags) +func (p *JSONPacker) PackObject(builder func(proteus.ObjectPackBuilder, proteus.Flags), flags proteus.Flags) { + p.packCompound('{','}',builder==nil,func(pk *JSONPacker, fl proteus.Flags){ builder(pk,fl) },flags) } -func (p *JSONPacker) packCompound (opener, closer byte, isnil bool, buildFn func(*JSONPacker, packs.Flags), flags packs.Flags) { +func (p *JSONPacker) packCompound (opener, closer byte, isnil bool, buildFn func(*JSONPacker, proteus.Flags), flags proteus.Flags) { if p.state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(p.state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(p.state.Error)) } if isnil { p.state.W(cjson.G.NullValue) @@ -229,9 +229,9 @@ func (p *JSONPacker) packCompound (opener, closer byte, isnil bool, buildFn func -func packRaw (state *packs.State, value []byte, flags packs.Flags) { +func packRaw (state *proteus.State, value []byte, flags proteus.Flags) { if state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error)) } if value == nil { state.W(cjson.G.NullValue) @@ -244,9 +244,9 @@ func packRaw (state *packs.State, value []byte, flags packs.Flags) { state.WOQ(flags.Quote(),'"',value) } -func packString (state *packs.State, value string , flags packs.Flags) { +func packString (state *proteus.State, value string , flags proteus.Flags) { if state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error)) } if len(value) == 0 { @@ -255,7 +255,7 @@ func packString (state *packs.State, value string , flags packs.Flags) { } if flags.Encrypted() { - packEncrypted(state, []byte(value), flags|packs.FlagBinary64) + packEncrypted(state, []byte(value), flags|proteus.FlagBinary64) return } @@ -268,7 +268,7 @@ func packString (state *packs.State, value string , flags packs.Flags) { } -func packEncrypted (state *packs.State, value []byte, flags packs.Flags) { +func packEncrypted (state *proteus.State, value []byte, flags proteus.Flags) { r := state.Encrypter.Encrypt(value) if !r.Ok() { state.SetError(r.Fail()) @@ -276,16 +276,16 @@ func packEncrypted (state *packs.State, value []byte, flags packs.Flags) { } if !flags.Binary() { - flags|= packs.FlagBinary64 + flags|= proteus.FlagBinary64 } packBinary(state,value,flags) } -func packBinary (state *packs.State, value []byte , flags packs.Flags) { +func packBinary (state *proteus.State, value []byte , flags proteus.Flags) { if state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error)) } if flags.Bin64() { @@ -296,48 +296,48 @@ func packBinary (state *packs.State, value []byte , flags packs.Flags) { state.SetError(cjson.WriteBase32(state.ABuffer,value)) return } - state.SetError(packs.G.ErrUnsupportedType) + state.SetError(proteus.G.ErrUnsupportedType) } -func packBool (state *packs.State, value bool , flags packs.Flags) { +func packBool (state *proteus.State, value bool , flags proteus.Flags) { if state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error)) } cjson.WriteBool(state.ABuffer,value,flags.Quote()) } -func packInt (state *packs.State, value int64 , flags packs.Flags) { +func packInt (state *proteus.State, value int64 , flags proteus.Flags) { if state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error)) } cjson.WriteInt(state.ABuffer,value,flags.Quote()) } -func packUInt (state *packs.State, value uint64 , flags packs.Flags) { +func packUInt (state *proteus.State, value uint64 , flags proteus.Flags) { if state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error)) } cjson.WriteUint(state.ABuffer,value,flags.Quote()) } -func packFloat (state *packs.State, value float64, flags packs.Flags) { +func packFloat (state *proteus.State, value float64, flags proteus.Flags) { packFloatString(state, value, flags, 64) } -func packFloatString (state *packs.State, f float64, flags packs.Flags, bits int) { +func packFloatString (state *proteus.State, f float64, flags proteus.Flags, bits int) { if state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error)) } cjson.WriteFloat(state.ABuffer,f,bits,flags.Quote()) } -func packDate(state *packs.State, value time.Time, flags packs.Flags) { +func packDate(state *proteus.State, value time.Time, flags proteus.Flags) { if state.Error != nil { - panic(packs.G.ErrInvalidState.WrapWithCause(state.Error)) + panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error)) } cjson.WriteDate(state.ABuffer,value,flags.DateFormat(),true) } @@ -347,7 +347,7 @@ func packDate(state *packs.State, value time.Time, flags packs.Flags) { -func packListString (state *packs.State, list []string, flags packs.Flags) { +func packListString (state *proteus.State, list []string, flags proteus.Flags) { if !checkList(state,list == nil, len(list) ==0) { return } @@ -365,7 +365,7 @@ func packListString (state *packs.State, list []string, flags packs.Flags) { } -func packListBool (state *packs.State, list []bool, flags packs.Flags) { +func packListBool (state *proteus.State, list []bool, flags proteus.Flags) { if !checkList(state,list == nil, len(list) ==0) { return } @@ -383,7 +383,7 @@ func packListBool (state *packs.State, list []bool, flags packs.Flags) { } -func packListInt [T int | int8 | int16 | int32 | int64](state *packs.State, list []T, flags packs.Flags) { +func packListInt [T int | int8 | int16 | int32 | int64](state *proteus.State, list []T, flags proteus.Flags) { if !checkList(state,list == nil, len(list) ==0) { return } @@ -401,7 +401,7 @@ func packListInt [T int | int8 | int16 | int32 | int64](state *packs.State, lis } -func packListUInt [T uint | uint8 | uint16 | uint32 | uint64](state *packs.State, list []T, flags packs.Flags) { +func packListUInt [T uint | uint8 | uint16 | uint32 | uint64](state *proteus.State, list []T, flags proteus.Flags) { if !checkList(state,list == nil, len(list) ==0) { return } @@ -419,7 +419,7 @@ func packListUInt [T uint | uint8 | uint16 | uint32 | uint64](state *packs.State } -func packListFloat[T float32 | float64](state *packs.State, list []T, flags packs.Flags, bits int) { +func packListFloat[T float32 | float64](state *proteus.State, list []T, flags proteus.Flags, bits int) { if !checkList(state,list == nil, len(list) ==0) { return } @@ -436,7 +436,7 @@ func packListFloat[T float32 | float64](state *packs.State, list []T, flags pack state.WriteByte(']') } -func packListDate (state *packs.State, list []time.Time, flags packs.Flags) { +func packListDate (state *proteus.State, list []time.Time, flags proteus.Flags) { if !checkList(state,list == nil, len(list) ==0) { return } @@ -454,7 +454,7 @@ func packListDate (state *packs.State, list []time.Time, flags packs.Flags) { } -func checkList (state *packs.State, isNull, isEmpty bool) bool { +func checkList (state *proteus.State, isNull, isEmpty bool) bool { if isNull { state.Write2Byte('"','"') return false diff --git a/proteus/pjson/list_pack_builder.go b/proteus/pjson/list_pack_builder.go new file mode 100644 index 0000000..b2e6948 --- /dev/null +++ b/proteus/pjson/list_pack_builder.go @@ -0,0 +1,80 @@ +// ------------------------------------------------------------------------ +// Project atila +// Active Thing (activething.com) git.activething.com/go +// +// File name builder_list.go +// Created by DEV +// Modified 06/02/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 pjson + +import ( + "packs" + "time" +) + +func (p *JSONPacker) ItemAny (value any, flags proteus.Flags) { p.addItem(func(){ p.PackAny(value,flags) }) } + + +func (p *JSONPacker) ItemRaw (value []byte, flags proteus.Flags) { p.addItem(func() { p.PackRaw(value,flags) }) } + +func (p *JSONPacker) ItemBinary (value []byte, flags proteus.Flags) { p.addItem(func (){ p.PackBinary(value,flags) }) } + +func (p *JSONPacker) ItemString (value string, flags proteus.Flags) { p.addItem(func (){ p.PackString(value,flags) }) } + + +func (p *JSONPacker) ItemBool (value bool, flags proteus.Flags) { p.addItem(func (){ p.PackBool(value,flags) }) } + +func (p *JSONPacker) ItemInt8 (value int8 , flags proteus.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) } +func (p *JSONPacker) ItemInt16 (value int16, flags proteus.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) } +func (p *JSONPacker) ItemInt32 (value int32, flags proteus.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) } +func (p *JSONPacker) ItemInt64 (value int64, flags proteus.Flags) { p.addItem(func (){ packInt(p.state,value,flags) }) } + +func (p *JSONPacker) ItemUInt8 (value uint8 , flags proteus.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) } +func (p *JSONPacker) ItemUInt16 (value uint16, flags proteus.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) } +func (p *JSONPacker) ItemUInt32 (value uint32, flags proteus.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) } +func (p *JSONPacker) ItemUInt64 (value uint64, flags proteus.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) } + +func (p *JSONPacker) ItemFloat32 (value float32, flags proteus.Flags){ p.addItem(func (){ packFloatString(p.state,float64(value),flags,32)})} +func (p *JSONPacker) ItemFloat64 (value float64, flags proteus.Flags){ p.addItem(func (){ packFloatString(p.state,value,flags,64) })} + +func (p *JSONPacker) ItemDate (value time.Time, flags proteus.Flags) { p.addItem(func(){ packDate(p.state,value,flags); p.state.Inc() })} + + +func (p *JSONPacker) ItemList (builder func(proteus.ListPackBuilder, proteus.Flags), flags proteus.Flags) { + p.addItem(func(){ p.PackList(builder,flags) }) } + +func (p *JSONPacker) ItemMap (builder func(proteus.MapPackBuilder, proteus.Flags), flags proteus.Flags) { + p.addItem(func(){ p.PackMap(builder,flags) }) } + +func (p *JSONPacker) ItemObject(builder func(proteus.ObjectPackBuilder, proteus.Flags), flags proteus.Flags) { + p.addItem(func(){ p.PackObject(builder,flags) }) } + + + +func (p *JSONPacker) addItem (caller func()) { + if p.state.Count() > 0 { + p.state.WriteByte(',') + } + caller() + if p.state != nil { + p.state.Inc() + } +} + + diff --git a/packs/pjson/map_pack_builder.go b/proteus/pjson/map_pack_builder.go similarity index 68% rename from packs/pjson/map_pack_builder.go rename to proteus/pjson/map_pack_builder.go index 0c3898d..7e8f033 100644 --- a/packs/pjson/map_pack_builder.go +++ b/proteus/pjson/map_pack_builder.go @@ -29,51 +29,51 @@ import ( "time" ) -func (p *JSONPacker) KeyValueAny (key any, value any, flags packs.Flags) { +func (p *JSONPacker) KeyValueAny (key any, value any, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackAny(value,flags)}) } -func (p *JSONPacker) KeyValueRaw (key any,value []byte, flags packs.Flags) { +func (p *JSONPacker) KeyValueRaw (key any,value []byte, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackRaw(value,flags)}) } -func (p *JSONPacker) KeyValueBinary (key any, value []byte, flags packs.Flags) { +func (p *JSONPacker) KeyValueBinary (key any, value []byte, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackBinary(value,flags)}) } -func (p *JSONPacker) KeyValueString (key any, value string, flags packs.Flags) { +func (p *JSONPacker) KeyValueString (key any, value string, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackString(value,flags)}) } -func (p *JSONPacker) KeyValueBool (key any, value bool, flags packs.Flags) { +func (p *JSONPacker) KeyValueBool (key any, value bool, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackBool(value,flags)}) } -func (p *JSONPacker) KeyValueInt8 (key any, value int8 , flags packs.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) } -func (p *JSONPacker) KeyValueInt16 (key any, value int16, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) } -func (p *JSONPacker) KeyValueInt32 (key any, value int32, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) } -func (p *JSONPacker) KeyValueInt64 (key any, value int64, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackInt64(value,flags)}) } +func (p *JSONPacker) KeyValueInt8 (key any, value int8 , flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) } +func (p *JSONPacker) KeyValueInt16 (key any, value int16, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) } +func (p *JSONPacker) KeyValueInt32 (key any, value int32, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) } +func (p *JSONPacker) KeyValueInt64 (key any, value int64, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackInt64(value,flags)}) } -func (p *JSONPacker) KeyValueUInt8 (key any, value uint8 , flags packs.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) } -func (p *JSONPacker) KeyValueUInt16 (key any, value uint16, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) } -func (p *JSONPacker) KeyValueUInt32 (key any, value uint32, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) } -func (p *JSONPacker) KeyValueUInt64 (key any, value uint64, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(value,flags)}) } +func (p *JSONPacker) KeyValueUInt8 (key any, value uint8 , flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) } +func (p *JSONPacker) KeyValueUInt16 (key any, value uint16, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) } +func (p *JSONPacker) KeyValueUInt32 (key any, value uint32, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) } +func (p *JSONPacker) KeyValueUInt64 (key any, value uint64, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(value,flags)}) } -func (p *JSONPacker) KeyValueFloat32(key any, value float32, flags packs.Flags){ +func (p *JSONPacker) KeyValueFloat32(key any, value float32, flags proteus.Flags){ p.addKeyValue(key,func(){ p.PackFloat32(value, flags) }) } -func (p *JSONPacker) KeyValueFloat64(key any, value float64, flags packs.Flags){ +func (p *JSONPacker) KeyValueFloat64(key any, value float64, flags proteus.Flags){ p.addKeyValue(key,func(){ p.PackFloat64(value, flags) }) } -func (p *JSONPacker) KeyValueDate (key any, value time.Time, flags packs.Flags){ +func (p *JSONPacker) KeyValueDate (key any, value time.Time, flags proteus.Flags){ p.addKeyValue(key,func(){ p.PackDate(value, flags) }) } -func (p *JSONPacker) KeyValueList (key any, builder func(packs.ListPackBuilder, packs.Flags), flags packs.Flags) { +func (p *JSONPacker) KeyValueList (key any, builder func(proteus.ListPackBuilder, proteus.Flags), flags proteus.Flags) { p.addKeyValue(key,func(){ p.PackList(builder, flags) }) } -func (p *JSONPacker) KeyValueMap (key any, builder func(packs.MapPackBuilder, packs.Flags), flags packs.Flags) { +func (p *JSONPacker) KeyValueMap (key any, builder func(proteus.MapPackBuilder, proteus.Flags), flags proteus.Flags) { p.addKeyValue(key,func(){ p.PackMap(builder, flags) }) } -func (p *JSONPacker) KeyValueObject (key any, builder func(packs.ObjectPackBuilder, packs.Flags), flags packs.Flags) { +func (p *JSONPacker) KeyValueObject (key any, builder func(proteus.ObjectPackBuilder, proteus.Flags), flags proteus.Flags) { p.addKeyValue(key,func(){ p.PackObject(builder, flags) }) } @@ -94,16 +94,16 @@ func (p *JSONPacker) addKeyValue(key any, caller func()) { func (p *JSONPacker) packStringifyKey(key any) { switch v := key.(type) { - case string : p.PackString(v, packs.FlagScapeHTML) - case float32: p.PackFloat32(v, packs.FlagScapeHTML|packs.FlagQuote) - case float64: p.PackFloat64(v, packs.FlagScapeHTML|packs.FlagQuote) + case string : p.PackString(v, proteus.FlagScapeHTML) + case float32: p.PackFloat32(v, proteus.FlagScapeHTML|proteus.FlagQuote) + case float64: p.PackFloat64(v, proteus.FlagScapeHTML|proteus.FlagQuote) default: me := &rMapEntry{ v : reflect.ValueOf(key), } fn := stringifyRKey(me.v.Type()) if fn == nil { - p.state.SetError(packs.G.ErrInvalidKey) + p.state.SetError(proteus.G.ErrInvalidKey) return } if er := fn(me,me.v); er != nil { diff --git a/packs/pjson/object_pack_builder.go b/proteus/pjson/object_pack_builder.go similarity index 82% rename from packs/pjson/object_pack_builder.go rename to proteus/pjson/object_pack_builder.go index 48439e2..b584483 100644 --- a/packs/pjson/object_pack_builder.go +++ b/proteus/pjson/object_pack_builder.go @@ -28,71 +28,71 @@ import ( "time" ) -func (p *JSONPacker) FieldAny (name string, value any, flags packs.Flags) { +func (p *JSONPacker) FieldAny (name string, value any, flags proteus.Flags) { p.addField(name, func() { p.PackAny(value, flags) }) } -func (p *JSONPacker) FieldRaw (name string, value []byte, flags packs.Flags){ +func (p *JSONPacker) FieldRaw (name string, value []byte, flags proteus.Flags){ p.addField(name, func() { p.PackRaw(value, flags) }) } -func (p *JSONPacker) FieldBinary (name string, value []byte, flags packs.Flags) { +func (p *JSONPacker) FieldBinary (name string, value []byte, flags proteus.Flags) { p.addField(name, func() { p.PackBinary(value, flags) }) } -func (p *JSONPacker) FieldString (name string, value string, flags packs.Flags) { +func (p *JSONPacker) FieldString (name string, value string, flags proteus.Flags) { p.addField(name, func() { p.PackString(value, flags) }) } -func (p *JSONPacker) FieldBool (name string, value bool, flags packs.Flags) { +func (p *JSONPacker) FieldBool (name string, value bool, flags proteus.Flags) { p.addField(name, func() { p.PackBool(value, flags) }) } -func (p *JSONPacker) FieldInt8 (name string, value int8 , flags packs.Flags) { +func (p *JSONPacker) FieldInt8 (name string, value int8 , flags proteus.Flags) { p.addField(name, func() { p.PackInt64(int64(value), flags) })} -func (p *JSONPacker) FieldInt16 (name string, value int16, flags packs.Flags) { +func (p *JSONPacker) FieldInt16 (name string, value int16, flags proteus.Flags) { p.addField(name, func() { p.PackInt64(int64(value), flags) })} -func (p *JSONPacker) FieldInt32 (name string, value int32, flags packs.Flags) { +func (p *JSONPacker) FieldInt32 (name string, value int32, flags proteus.Flags) { p.addField(name, func() { p.PackInt64(int64(value), flags) }) } -func (p *JSONPacker) FieldInt64 (name string, value int64, flags packs.Flags) { +func (p *JSONPacker) FieldInt64 (name string, value int64, flags proteus.Flags) { p.addField(name, func() { p.PackInt64(value, flags) }) } -func (p *JSONPacker) FieldUInt8 (name string, value uint8, flags packs.Flags) { +func (p *JSONPacker) FieldUInt8 (name string, value uint8, flags proteus.Flags) { p.addField(name, func() { p.PackUInt64(uint64(value), flags) }) } -func (p *JSONPacker) FieldUInt16 (name string, value uint16, flags packs.Flags) { +func (p *JSONPacker) FieldUInt16 (name string, value uint16, flags proteus.Flags) { p.addField(name,func(){ p.PackUInt64(uint64(value), flags) }) } -func (p *JSONPacker) FieldUInt32 (name string, value uint32, flags packs.Flags) { +func (p *JSONPacker) FieldUInt32 (name string, value uint32, flags proteus.Flags) { p.addField(name,func(){ p.PackUInt64(uint64(value), flags) }) } -func (p *JSONPacker) FieldUInt64 (name string, value uint64, flags packs.Flags) { +func (p *JSONPacker) FieldUInt64 (name string, value uint64, flags proteus.Flags) { p.addField(name,func(){ p.PackUInt64(value, flags) }) } -func (p *JSONPacker) FieldFloat32(name string, value float32,flags packs.Flags) { +func (p *JSONPacker) FieldFloat32(name string, value float32,flags proteus.Flags) { p.addField(name,func(){ p.PackFloat32(value, flags) }) } -func (p *JSONPacker) FieldFloat64(name string, value float64,flags packs.Flags) { +func (p *JSONPacker) FieldFloat64(name string, value float64,flags proteus.Flags) { p.addField(name,func(){ p.PackFloat64(value, flags) }) } -func (p *JSONPacker) FieldDate (name string, value time.Time,flags packs.Flags) { +func (p *JSONPacker) FieldDate (name string, value time.Time,flags proteus.Flags) { p.addField(name,func(){ p.PackDate(value, flags) }) } -func (p *JSONPacker) FieldList (name string, builder func(packs.ListPackBuilder, packs.Flags), flags packs.Flags) { +func (p *JSONPacker) FieldList (name string, builder func(proteus.ListPackBuilder, proteus.Flags), flags proteus.Flags) { p.addField(name,func(){ p.PackList(builder, flags) }) } -func (p *JSONPacker) FieldMap (name string, builder func(packs.MapPackBuilder, packs.Flags), flags packs.Flags) { +func (p *JSONPacker) FieldMap (name string, builder func(proteus.MapPackBuilder, proteus.Flags), flags proteus.Flags) { p.addField(name,func(){ p.PackMap(builder, flags) }) } -func (p *JSONPacker) FieldObject (name string, builder func(packs.ObjectPackBuilder, packs.Flags), flags packs.Flags) { +func (p *JSONPacker) FieldObject (name string, builder func(proteus.ObjectPackBuilder, proteus.Flags), flags proteus.Flags) { p.addField(name,func(){ p.PackObject(builder, flags) }) } @@ -102,7 +102,7 @@ func (p *JSONPacker) addField(name string, caller func()) { if p.state.Count() > 0 { p.state.WriteByte(',') } - packString(p.state,name, packs.FlagScapeHTML) + packString(p.state,name, proteus.FlagScapeHTML) if p.state.Error != nil { return } diff --git a/packs/pjson/rpacker.go b/proteus/pjson/rpacker.go similarity index 67% rename from packs/pjson/rpacker.go rename to proteus/pjson/rpacker.go index 321d322..947b68c 100644 --- a/packs/pjson/rpacker.go +++ b/proteus/pjson/rpacker.go @@ -33,7 +33,7 @@ type ( - rPackerFnc func (state *packs.State, rvalue reflect.Value, flags packs.Flags) + rPackerFnc func (state *proteus.State, rvalue reflect.Value, flags proteus.Flags) ) @@ -49,7 +49,7 @@ func rTypePacker (rtype reflect.Type) rPackerFnc { wg.Add(1) - fi,ld := g.packersCache.LoadOrStore(rtype, rPackerFnc(func (e *packs.State, v reflect.Value, f packs.Flags) { + fi,ld := g.packersCache.LoadOrStore(rtype, rPackerFnc(func (e *proteus.State, v reflect.Value, f proteus.Flags) { wg.Wait() fn(e,v,f) })) @@ -68,20 +68,20 @@ func rTypePacker (rtype reflect.Type) rPackerFnc { func _rTypePacker(rtype reflect.Type) rPackerFnc { switch rtype.Kind() { - case reflect.Bool : return func(s *packs.State, v reflect.Value, f packs.Flags) { packBool (s,v.Bool (),f )} - case reflect.String : return func(s *packs.State, v reflect.Value, f packs.Flags) { packString(s,v.String(),f )} + case reflect.Bool : return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packBool (s,v.Bool (),f )} + case reflect.String : return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packString(s,v.String(),f )} case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, - reflect.Int64 : return func(s *packs.State, v reflect.Value, f packs.Flags) { packInt (s,v.Int (),f )} + reflect.Int64 : return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packInt (s,v.Int (),f )} case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, - reflect.Uint64 : return func(s *packs.State, v reflect.Value, f packs.Flags) { packUInt (s,v.Uint (),f )} - case reflect.Float32: return func(s *packs.State, v reflect.Value, f packs.Flags) { packFloatString(s,v.Float(),f,32) } - case reflect.Float64: return func(s *packs.State, v reflect.Value, f packs.Flags) { packFloatString(s,v.Float(),f,64) } + reflect.Uint64 : return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packUInt (s,v.Uint (),f )} + case reflect.Float32: return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packFloatString(s,v.Float(),f,32) } + case reflect.Float64: return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packFloatString(s,v.Float(),f,64) } case reflect.Pointer: return rPointerPacker(rtype) @@ -106,8 +106,8 @@ func _rTypePacker(rtype reflect.Type) rPackerFnc { } -func unsupportedTypePacker(state *packs.State, _ reflect.Value, _ packs.Flags) { - state.SetError(packs.G.ErrUnsupportedType) +func unsupportedTypePacker(state *proteus.State, _ reflect.Value, _ proteus.Flags) { + state.SetError(proteus.G.ErrUnsupportedType) } diff --git a/packs/pjson/rpacker_interface.go b/proteus/pjson/rpacker_interface.go similarity index 93% rename from packs/pjson/rpacker_interface.go rename to proteus/pjson/rpacker_interface.go index addee14..d6556d6 100644 --- a/packs/pjson/rpacker_interface.go +++ b/proteus/pjson/rpacker_interface.go @@ -29,7 +29,7 @@ import ( "reflect" ) -func rInterfacePacker (s *packs.State, v reflect.Value, f packs.Flags) { +func rInterfacePacker (s *proteus.State, v reflect.Value, f proteus.Flags) { if v.IsNil() { s.W(cjson.G.NullValue) return diff --git a/packs/pjson/rpacker_key.go b/proteus/pjson/rpacker_key.go similarity index 95% rename from packs/pjson/rpacker_key.go rename to proteus/pjson/rpacker_key.go index beb889e..370a1a1 100644 --- a/packs/pjson/rpacker_key.go +++ b/proteus/pjson/rpacker_key.go @@ -45,7 +45,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc { if rt.Kind() == reflect.String { return func(e *rMapEntry, k reflect.Value) error { e.k = k.String() - e.f = packs.FlagScapeHTML + e.f = proteus.FlagScapeHTML return nil } } @@ -58,7 +58,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc { bf, er := (k.Interface().(encoding.TextMarshaler)).MarshalText() if er == nil { e.k = string(bf) - e.f = packs.FlagScapeHTML + e.f = proteus.FlagScapeHTML } return er } @@ -92,7 +92,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc { if k.Type().Kind() == reflect.String { e.k = k.String() - e.f = packs.FlagScapeHTML + e.f = proteus.FlagScapeHTML return nil } @@ -103,7 +103,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc { bf, er := t.MarshalText() if er == nil { e.k = string(bf) - e.f = packs.FlagScapeHTML + e.f = proteus.FlagScapeHTML } return er } @@ -128,7 +128,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc { return nil default: - return packs.G.ErrInvalidKey + return proteus.G.ErrInvalidKey } } diff --git a/packs/pjson/rpacker_list.go b/proteus/pjson/rpacker_list.go similarity index 86% rename from packs/pjson/rpacker_list.go rename to proteus/pjson/rpacker_list.go index c75c453..fbdc84a 100644 --- a/packs/pjson/rpacker_list.go +++ b/proteus/pjson/rpacker_list.go @@ -58,7 +58,7 @@ func newRList(rtype reflect.Type) *rList { -func (p rList) packBinary (s *packs.State, v reflect.Value, f packs.Flags) { +func (p rList) packBinary (s *proteus.State, v reflect.Value, f proteus.Flags) { if f.Binary() { packBinary(s, v.Interface().([]byte), f) return @@ -67,7 +67,7 @@ func (p rList) packBinary (s *packs.State, v reflect.Value, f packs.Flags) { } -func (p rList) packBinarySlice (s *packs.State, v reflect.Value, f packs.Flags) { +func (p rList) packBinarySlice (s *proteus.State, v reflect.Value, f proteus.Flags) { if f.Binary() { packBinary(s, v.Interface().([]byte), f) return @@ -78,7 +78,7 @@ func (p rList) packBinarySlice (s *packs.State, v reflect.Value, f packs.Flags) -func (p rList) packSlice(s *packs.State, v reflect.Value, f packs.Flags) { +func (p rList) packSlice(s *proteus.State, v reflect.Value, f proteus.Flags) { if v.IsNil() { s.W(cjson.G.NullValue) return @@ -95,7 +95,7 @@ func (p rList) packSlice(s *packs.State, v reflect.Value, f packs.Flags) { if fn,ok := s.CheckCycle(cp); ok { defer fn() } else { - s.SetError(packs.G.ErrRedundantPack) + s.SetError(proteus.G.ErrRedundantPack) return } } @@ -105,7 +105,7 @@ func (p rList) packSlice(s *packs.State, v reflect.Value, f packs.Flags) { -func (p rList) pack (s *packs.State, v reflect.Value, f packs.Flags) { +func (p rList) pack (s *proteus.State, v reflect.Value, f proteus.Flags) { if v.IsNil() { s.W(cjson.G.NullValue) return diff --git a/packs/pjson/rpacker_map.go b/proteus/pjson/rpacker_map.go similarity index 93% rename from packs/pjson/rpacker_map.go rename to proteus/pjson/rpacker_map.go index 85ce778..4b28d65 100644 --- a/packs/pjson/rpacker_map.go +++ b/proteus/pjson/rpacker_map.go @@ -53,9 +53,9 @@ func newRMap(rtype reflect.Type) *rMap { } -func (p *rMap) pack (s *packs.State, v reflect.Value, f packs.Flags) { +func (p *rMap) pack (s *proteus.State, v reflect.Value, f proteus.Flags) { if p.keyFn == nil { - s.SetError(packs.G.ErrInvalidKey) + s.SetError(proteus.G.ErrInvalidKey) return } @@ -72,7 +72,7 @@ func (p *rMap) pack (s *packs.State, v reflect.Value, f packs.Flags) { if fn,ok := s.CheckCycle(v.UnsafePointer()); ok { defer fn() } else { - s.SetError(packs.G.ErrRedundantPack) + s.SetError(proteus.G.ErrRedundantPack) return } } diff --git a/packs/pjson/rpacker_map_entry.go b/proteus/pjson/rpacker_map_entry.go similarity index 98% rename from packs/pjson/rpacker_map_entry.go rename to proteus/pjson/rpacker_map_entry.go index 75f3d56..29b2af2 100644 --- a/packs/pjson/rpacker_map_entry.go +++ b/proteus/pjson/rpacker_map_entry.go @@ -32,7 +32,7 @@ type ( rMapEntry struct { - f packs.Flags // flags + f proteus.Flags // flags v reflect.Value // value k string // Key } diff --git a/packs/pjson/rpacker_object.go b/proteus/pjson/rpacker_object.go similarity index 90% rename from packs/pjson/rpacker_object.go rename to proteus/pjson/rpacker_object.go index f507b77..4604b30 100644 --- a/packs/pjson/rpacker_object.go +++ b/proteus/pjson/rpacker_object.go @@ -46,7 +46,7 @@ func rObjectPacker (rtype reflect.Type) rPackerFnc { if !ok { op,_ = g.fieldsCache.LoadOrStore(rtype,*newRObject(rtype)) } - return func(s *packs.State, value reflect.Value, flags packs.Flags) { + return func(s *proteus.State, value reflect.Value, flags proteus.Flags) { op.(rObject).pack(s,value,flags) } //return (op.(rObject)).pack @@ -85,7 +85,7 @@ func newRObject(rtype reflect.Type) *rObject { continue } - nm, fg, has := packs.FlagsFromPackTag(sf.Tag) + nm, fg, has := proteus.FlagsFromPackTag(sf.Tag) if !has { nm, fg, has = jsonTags(sf.Tag) } @@ -93,7 +93,7 @@ func newRObject(rtype reflect.Type) *rObject { if nm == "-" || fg.Omit() { continue } - if !packs.CheckTag(nm) { + if !proteus.CheckTag(nm) { nm = "" } } @@ -114,7 +114,7 @@ func newRObject(rtype reflect.Type) *rObject { reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64, reflect.String: - fg = fg| packs.FlagQuote + fg = fg| proteus.FlagQuote } } @@ -131,7 +131,7 @@ func newRObject(rtype reflect.Type) *rObject { flags : fg, } of.nameB = []byte(of.name) - of.foldFn= packs.GetFoldFunc(of.nameB) + of.foldFn= proteus.GetFoldFunc(of.nameB) // Build nameEscHTML and nameNonEsc ahead of time. nms.Reset() @@ -211,7 +211,7 @@ func newRObject(rtype reflect.Type) *rObject { -func (o rObject) pack (s *packs.State, v reflect.Value, f packs.Flags) { +func (o rObject) pack (s *proteus.State, v reflect.Value, f proteus.Flags) { nx := byte('{') FieldLoop: for i:= range o.fields { @@ -248,11 +248,11 @@ FieldLoop: } -func jsonTags (tag reflect.StructTag) (string, packs.Flags,bool) { - return packs.FlagsFromTag(tag,jsonTag,func(n string) packs.Flags { +func jsonTags (tag reflect.StructTag) (string, proteus.Flags,bool) { + return proteus.FlagsFromTag(tag,jsonTag,func(n string) proteus.Flags { switch n { - case "omitempty" : return packs.FlagOmitEmpty - case "quote" : return packs.FlagQuote + case "omitempty" : return proteus.FlagOmitEmpty + case "quote" : return proteus.FlagQuote default : return 0 } }) diff --git a/packs/pjson/rpacker_object_field.go b/proteus/pjson/rpacker_object_field.go similarity index 97% rename from packs/pjson/rpacker_object_field.go rename to proteus/pjson/rpacker_object_field.go index 4c2c13d..2f3c1fe 100644 --- a/packs/pjson/rpacker_object_field.go +++ b/proteus/pjson/rpacker_object_field.go @@ -39,9 +39,9 @@ type ( isTagged bool index []int rtype reflect.Type - flags packs.Flags + flags proteus.Flags - foldFn packs.FoldFnc + foldFn proteus.FoldFnc packerFn rPackerFnc } diff --git a/packs/pjson/rpacker_pointer.go b/proteus/pjson/rpacker_pointer.go similarity index 95% rename from packs/pjson/rpacker_pointer.go rename to proteus/pjson/rpacker_pointer.go index 1466c91..8f6d9b6 100644 --- a/packs/pjson/rpacker_pointer.go +++ b/proteus/pjson/rpacker_pointer.go @@ -47,7 +47,7 @@ func newRPointer (rtype reflect.Type) *rPointer { } -func (p rPointer) pack (s *packs.State, v reflect.Value, f packs.Flags) { +func (p rPointer) pack (s *proteus.State, v reflect.Value, f proteus.Flags) { if v.IsNil() { s.W(cjson.G.NullValue) return diff --git a/packs/pjson/rpacker_value.go b/proteus/pjson/rpacker_value.go similarity index 90% rename from packs/pjson/rpacker_value.go rename to proteus/pjson/rpacker_value.go index 599da0a..77b4e88 100644 --- a/packs/pjson/rpacker_value.go +++ b/proteus/pjson/rpacker_value.go @@ -36,6 +36,6 @@ func rValuePacker (rvalue reflect.Value) rPackerFnc { } -func invalidValuePacker(state *packs.State, _ reflect.Value, _ packs.Flags) { - state.SetError(packs.G.ErrInvalidValue) +func invalidValuePacker(state *proteus.State, _ reflect.Value, _ proteus.Flags) { + state.SetError(proteus.G.ErrInvalidValue) } \ No newline at end of file diff --git a/packs/state.go b/proteus/state.go similarity index 96% rename from packs/state.go rename to proteus/state.go index f95ac1c..1a7ac8b 100644 --- a/packs/state.go +++ b/proteus/state.go @@ -21,13 +21,13 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus import ( "bins/mems" "crypts" "sync/atomic" - "syncs" + "syncs/pools" ) @@ -53,8 +53,8 @@ type ( func NewState(options ...StateFnc) *State { if atomic.CompareAndSwapUint32(&g.poolsSem,0,1) { - g.statePool = syncs.NewPool[State]( - syncs.PoolWithNew[State](func() *State { + g.statePool = pools.NewGPool[State]( + pools.WithNew[State](func() *State { return &State{ ABuffer: mems.NewABuffer(), checks : make(map[any]struct{}), diff --git a/packs/value_packer.go b/proteus/value_packer.go similarity index 99% rename from packs/value_packer.go rename to proteus/value_packer.go index 41b6bd1..91f4eed 100644 --- a/packs/value_packer.go +++ b/proteus/value_packer.go @@ -21,7 +21,7 @@ // limitations under the License. // ------------------------------------------------------------------------ -package packs +package proteus import "time"