parent
33e4d8a6ab
commit
848ea1e78c
@ -0,0 +1,55 @@
|
||||
/*
|
||||
---------------------------------------------------------
|
||||
Project activething
|
||||
Active Thing (activething.com) git.activething.com/go
|
||||
|
||||
File name err_causer.go
|
||||
Created by DEV
|
||||
Modified 23/10/2023
|
||||
|
||||
Copyright 2023 activething.com
|
||||
---------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
*/
|
||||
|
||||
package errs
|
||||
|
||||
type (
|
||||
|
||||
// Causer
|
||||
// Define un interface para los objetos que implementan la información sobre un error
|
||||
// previo causante del error
|
||||
Causer interface {
|
||||
Cause() error
|
||||
}
|
||||
|
||||
// CauserFnc
|
||||
// Función para ser llamada para obtener el error causante
|
||||
CauserFnc func() error
|
||||
)
|
||||
|
||||
func (f CauserFnc) Cause() error { return f() }
|
||||
|
||||
/*
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
||||
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
||||
|
||||
SIDDHARTA
|
||||
- HERMANN HESSE -
|
||||
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
*/
|
||||
@ -0,0 +1,75 @@
|
||||
/*
|
||||
---------------------------------------------------------
|
||||
Project activething
|
||||
Active Thing (activething.com) git.activething.com/go
|
||||
|
||||
File name err_cause.go
|
||||
Created by DEV
|
||||
Modified 23/10/2023
|
||||
|
||||
Copyright 2023 activething.com
|
||||
---------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
*/
|
||||
|
||||
package errs
|
||||
|
||||
import "activething.com/go/gogo/core/opts"
|
||||
|
||||
type (
|
||||
|
||||
// ErrCause
|
||||
// Define una estructura para almacenar un error y su causa previa
|
||||
// Implmenta error, Unwrap
|
||||
//
|
||||
ErrCause struct {
|
||||
error
|
||||
cause error
|
||||
}
|
||||
)
|
||||
|
||||
func NewErrCause(err, cause error) *ErrCause {
|
||||
if err == nil {
|
||||
if cause == nil {
|
||||
return nil
|
||||
}
|
||||
return &ErrCause{error: cause}
|
||||
}
|
||||
return &ErrCause{error: err, cause: cause}
|
||||
}
|
||||
|
||||
func (e ErrCause) WithInfo(options ...opts.OptionFnc[ErrInfo]) *ErrInfo {
|
||||
return NewErrInfo(e, options...)
|
||||
}
|
||||
|
||||
func (e ErrCause) Stack() StackTrace {
|
||||
return getStackTrace(e.cause)
|
||||
}
|
||||
|
||||
func (e ErrCause) Cause() error { return e.cause }
|
||||
|
||||
func (e ErrCause) Unwrap() error { return e.cause }
|
||||
|
||||
/*
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
||||
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
||||
|
||||
SIDDHARTA
|
||||
- HERMANN HESSE -
|
||||
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
*/
|
||||
@ -0,0 +1,78 @@
|
||||
/*
|
||||
---------------------------------------------------------
|
||||
Project activething
|
||||
Active Thing (activething.com) git.activething.com/go
|
||||
|
||||
File name err_group.go
|
||||
Created by DEV
|
||||
Modified 23/10/2023
|
||||
|
||||
Copyright 2023 activething.com
|
||||
---------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
*/
|
||||
|
||||
package errs
|
||||
|
||||
import "activething.com/go/gogo/core/opts"
|
||||
|
||||
type ErrGroup ErrList
|
||||
|
||||
func (_ ErrGroup) Error() string {
|
||||
return "core:errs.group-error"
|
||||
}
|
||||
|
||||
func (g ErrGroup) Count() int {
|
||||
return len(g)
|
||||
}
|
||||
|
||||
func (g ErrGroup) Errors() []error {
|
||||
return g
|
||||
}
|
||||
|
||||
func (g ErrGroup) Cause() error {
|
||||
switch len(g) {
|
||||
case 0:
|
||||
return nil
|
||||
case 1:
|
||||
return g[0]
|
||||
default:
|
||||
return ErrGroup(g[1:])
|
||||
}
|
||||
}
|
||||
|
||||
func (g ErrGroup) Unwrap() error {
|
||||
return g.Cause()
|
||||
}
|
||||
|
||||
func (g ErrGroup) Stack() StackTrace {
|
||||
return g.Stack()
|
||||
}
|
||||
|
||||
func (g ErrGroup) WithInfo(options ...opts.OptionFnc[ErrInfo]) *ErrInfo {
|
||||
return NewErrInfo(g, options...)
|
||||
}
|
||||
|
||||
/*
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
||||
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
||||
|
||||
SIDDHARTA
|
||||
- HERMANN HESSE -
|
||||
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
*/
|
||||
@ -0,0 +1,169 @@
|
||||
/*
|
||||
---------------------------------------------------------
|
||||
Project activething
|
||||
Active Thing (activething.com) git.activething.com/go
|
||||
|
||||
File name err_info.go
|
||||
Created by DEV
|
||||
Modified 23/10/2023
|
||||
|
||||
Copyright 2023 activething.com
|
||||
---------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
*/
|
||||
|
||||
package errs
|
||||
|
||||
import (
|
||||
"activething.com/go/gogo/core/opts"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
// ErrInfo
|
||||
// Representa un objeto para añadir una capa de información addicional a un error
|
||||
//
|
||||
ErrInfo struct {
|
||||
/*embedded*/ error
|
||||
|
||||
date time.Time
|
||||
source string
|
||||
help string
|
||||
message string
|
||||
link string
|
||||
details map[string]any
|
||||
stack StackTrace
|
||||
}
|
||||
)
|
||||
|
||||
func NewErrInfo(err error, options ...opts.OptionFnc[ErrInfo]) *ErrInfo {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return opts.Apply(&ErrInfo{error: err}, options...)
|
||||
}
|
||||
|
||||
func (i ErrInfo) Message() string {
|
||||
return i.message
|
||||
}
|
||||
|
||||
func (i ErrInfo) Source() string {
|
||||
return i.source
|
||||
}
|
||||
|
||||
func (i ErrInfo) Help() string {
|
||||
return i.help
|
||||
}
|
||||
|
||||
func (i ErrInfo) Link() string {
|
||||
return i.link
|
||||
}
|
||||
|
||||
func (i ErrInfo) Stack() StackTrace {
|
||||
if i.stack != nil {
|
||||
return i.stack
|
||||
}
|
||||
return getStackTrace(i.Cause())
|
||||
}
|
||||
|
||||
func (i ErrInfo) Details() map[string]any {
|
||||
return i.Details()
|
||||
}
|
||||
|
||||
func (i ErrInfo) Cause() error {
|
||||
if cs, is := i.error.(Causer); is {
|
||||
return cs.Cause()
|
||||
}
|
||||
return Unwrap(i.error)
|
||||
}
|
||||
|
||||
func (i ErrInfo) Unwrap() error {
|
||||
return i.Cause()
|
||||
}
|
||||
|
||||
func (i ErrInfo) Date() time.Time { return i.date }
|
||||
|
||||
func ErrInfoWithCause(cause error) opts.OptionFnc[ErrInfo] {
|
||||
return func(i *ErrInfo) {
|
||||
if cause == nil {
|
||||
return
|
||||
}
|
||||
i.error = NewErrCause(i.error, cause)
|
||||
}
|
||||
}
|
||||
|
||||
func ErrInfoWithMessage(message string) opts.OptionFnc[ErrInfo] {
|
||||
return func(i *ErrInfo) {
|
||||
i.message = message
|
||||
}
|
||||
}
|
||||
|
||||
func ErrInfoWithMessagef(format string, args ...any) opts.OptionFnc[ErrInfo] {
|
||||
return func(i *ErrInfo) {
|
||||
i.message = fmt.Sprintf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func ErrInfoWithLink(link string) opts.OptionFnc[ErrInfo] {
|
||||
return func(i *ErrInfo) {
|
||||
i.link = link
|
||||
}
|
||||
}
|
||||
|
||||
func ErrInfoWithHelp(help string) opts.OptionFnc[ErrInfo] {
|
||||
return func(i *ErrInfo) {
|
||||
i.help = help
|
||||
}
|
||||
}
|
||||
|
||||
func ErrInfoWithDate() opts.OptionFnc[ErrInfo] {
|
||||
return func(i *ErrInfo) { i.date = time.Now() }
|
||||
}
|
||||
|
||||
func ErrInfoWithStack(offset ...int) opts.OptionFnc[ErrInfo] {
|
||||
return func(i *ErrInfo) {
|
||||
if len(i.stack) > 0 {
|
||||
return
|
||||
}
|
||||
ox := 3
|
||||
if len(offset) > 0 {
|
||||
ox = offset[0]
|
||||
}
|
||||
i.stack = *NewStackTrace(ox)
|
||||
}
|
||||
}
|
||||
|
||||
func ErrInfoWithDetail(name string, value any) opts.OptionFnc[ErrInfo] {
|
||||
return func(i *ErrInfo) {
|
||||
if i.details == nil {
|
||||
i.details = make(map[string]any)
|
||||
}
|
||||
i.details[name] = value
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
||||
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
||||
|
||||
SIDDHARTA
|
||||
- HERMANN HESSE -
|
||||
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
*/
|
||||
@ -0,0 +1,135 @@
|
||||
/*
|
||||
---------------------------------------------------------
|
||||
Project activething
|
||||
Active Thing (activething.com) git.activething.com/go
|
||||
|
||||
File name err_list.go
|
||||
Created by DEV
|
||||
Modified 23/10/2023
|
||||
|
||||
Copyright 2023 activething.com
|
||||
---------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
*/
|
||||
|
||||
package errs
|
||||
|
||||
type ErrList []error
|
||||
|
||||
func (l ErrList) Clean() ErrList {
|
||||
for _, e := range l {
|
||||
if e == nil {
|
||||
return l.clean()
|
||||
}
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ErrList) clean() ErrList {
|
||||
rs := make([]error, 0, len(l))
|
||||
for _, e := range l {
|
||||
if e != nil {
|
||||
rs = append(rs, e)
|
||||
}
|
||||
}
|
||||
return rs
|
||||
}
|
||||
|
||||
func (l ErrList) GetFirst() error {
|
||||
for _, er := range l {
|
||||
if er != nil {
|
||||
return er
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l ErrList) GetLast() error {
|
||||
for i := len(l) - 1; i >= 0; i-- {
|
||||
if l[i] != nil {
|
||||
return l[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l ErrList) Any() bool {
|
||||
return l.count(true) > 0
|
||||
}
|
||||
|
||||
func (l ErrList) Count() int {
|
||||
return _errorsCount(false, l)
|
||||
}
|
||||
|
||||
func (l ErrList) count(ext bool) int {
|
||||
rs := 0
|
||||
for _, er := range l {
|
||||
if er != nil {
|
||||
if ext {
|
||||
return 1
|
||||
}
|
||||
rs++
|
||||
}
|
||||
}
|
||||
return rs
|
||||
}
|
||||
|
||||
func (l ErrList) Stack() StackTrace {
|
||||
for _, er := range l {
|
||||
if er != nil {
|
||||
st := getStackTrace(er)
|
||||
if st != nil {
|
||||
return st
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l ErrList) ToError() error {
|
||||
switch _errorsCount(false, l) {
|
||||
case 0:
|
||||
return nil
|
||||
case 1:
|
||||
return l.GetFirst()
|
||||
default:
|
||||
return ErrGroup(l)
|
||||
}
|
||||
}
|
||||
|
||||
func _errorsCount(exitOnAny bool, els []error) int {
|
||||
rs := 0
|
||||
for _, er := range els {
|
||||
if er != nil {
|
||||
rs++
|
||||
if exitOnAny {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return rs
|
||||
}
|
||||
|
||||
/*
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
||||
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
||||
|
||||
SIDDHARTA
|
||||
- HERMANN HESSE -
|
||||
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
*/
|
||||
@ -0,0 +1,53 @@
|
||||
/*
|
||||
---------------------------------------------------------
|
||||
Project activething
|
||||
Active Thing (activething.com) git.activething.com/go
|
||||
|
||||
File name err_info.go
|
||||
Created by DEV
|
||||
Modified 23/10/2023
|
||||
|
||||
Copyright 2023 activething.com
|
||||
---------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
*/
|
||||
|
||||
package errs
|
||||
|
||||
type (
|
||||
ErrorHandler interface {
|
||||
HandleError(err error)
|
||||
}
|
||||
|
||||
// ErrorHandlerFnc
|
||||
// Función que implementa el interface ErrorHandler
|
||||
ErrorHandlerFnc func(err error)
|
||||
)
|
||||
|
||||
func (f ErrorHandlerFnc) HandleError(err error) {
|
||||
f(err)
|
||||
}
|
||||
|
||||
/*
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
||||
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
||||
|
||||
SIDDHARTA
|
||||
- HERMANN HESSE -
|
||||
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
*/
|
||||
@ -0,0 +1,70 @@
|
||||
/*
|
||||
---------------------------------------------------------
|
||||
Project activething
|
||||
Active Thing (activething.com) git.activething.com/go
|
||||
|
||||
File name stack.go
|
||||
Created by DEV
|
||||
Modified 23/10/2023
|
||||
|
||||
Copyright 2023 activething.com
|
||||
---------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
*/
|
||||
|
||||
package errs
|
||||
|
||||
import "runtime"
|
||||
|
||||
const (
|
||||
stackMaxFrames = 32
|
||||
stackSkipFrames = 2
|
||||
)
|
||||
|
||||
type StackTrace []uintptr
|
||||
|
||||
func NewStackTrace(offset int) *StackTrace {
|
||||
var fm [stackMaxFrames]uintptr
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
cn := runtime.Callers(offset+stackSkipFrames, fm[:])
|
||||
st := StackTrace(fm[0:cn])
|
||||
return &st
|
||||
}
|
||||
|
||||
func (s StackTrace) Frames() []StackTraceFrame {
|
||||
ln := len(s)
|
||||
if ln == 0 {
|
||||
return nil
|
||||
}
|
||||
st := make([]StackTraceFrame, ln)
|
||||
for ix := 0; ix < ln; ix++ {
|
||||
st[ix] = StackTraceFrame(s[ix])
|
||||
}
|
||||
return st
|
||||
}
|
||||
|
||||
/*
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
||||
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
||||
|
||||
SIDDHARTA
|
||||
- HERMANN HESSE -
|
||||
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
*/
|
||||
@ -0,0 +1,97 @@
|
||||
/*
|
||||
---------------------------------------------------------
|
||||
Project activething
|
||||
Active Thing (activething.com) git.activething.com/go
|
||||
|
||||
File name stack_trace_frame.go
|
||||
Created by DEV
|
||||
Modified 23/10/2023
|
||||
|
||||
Copyright 2023 activething.com
|
||||
---------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
*/
|
||||
|
||||
package errs
|
||||
|
||||
import (
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
unknown string = "??"
|
||||
)
|
||||
|
||||
type StackTraceFrame uintptr
|
||||
|
||||
func (f StackTraceFrame) PC() uintptr { return uintptr(f) - 1 }
|
||||
|
||||
func (f StackTraceFrame) FileName() (fl string) {
|
||||
fl, _ = f.FileLine()
|
||||
return
|
||||
}
|
||||
|
||||
func (f StackTraceFrame) FileFull() string {
|
||||
return path.Base(f.FileName())
|
||||
}
|
||||
|
||||
func (f StackTraceFrame) Line() (ln int) {
|
||||
_, ln = f.FileLine()
|
||||
return
|
||||
}
|
||||
|
||||
func (f StackTraceFrame) FileLine() (string, int) {
|
||||
pc := f.PC()
|
||||
if fn := runtime.FuncForPC(pc); fn != nil {
|
||||
return fn.FileLine(pc)
|
||||
}
|
||||
return unknown, 0
|
||||
}
|
||||
|
||||
func (f StackTraceFrame) FuncName() string {
|
||||
return f.getFunc(true)
|
||||
}
|
||||
|
||||
func (f StackTraceFrame) FuncFull() string {
|
||||
return f.getFunc(false)
|
||||
}
|
||||
|
||||
func (f StackTraceFrame) getFunc(cls bool) string {
|
||||
if fn := runtime.FuncForPC(f.PC()); fn != nil {
|
||||
nm := fn.Name()
|
||||
if cls {
|
||||
ix := strings.LastIndex(nm, "/")
|
||||
nm = nm[ix+1:]
|
||||
ix = strings.Index(nm, ".")
|
||||
return nm[ix+1:]
|
||||
}
|
||||
return nm
|
||||
}
|
||||
return unknown
|
||||
}
|
||||
|
||||
/*
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
||||
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
||||
|
||||
SIDDHARTA
|
||||
- HERMANN HESSE -
|
||||
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
*/
|
||||
@ -0,0 +1,45 @@
|
||||
/*
|
||||
---------------------------------------------------------
|
||||
Project activething
|
||||
Active Thing (activething.com) git.activething.com/go
|
||||
|
||||
File name stack_tracer.go
|
||||
Created by DEV
|
||||
Modified 23/10/2023
|
||||
|
||||
Copyright 2023 activething.com
|
||||
---------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
*/
|
||||
|
||||
package errs
|
||||
|
||||
type (
|
||||
StackTracer interface {
|
||||
Stack() StackTrace
|
||||
}
|
||||
)
|
||||
|
||||
/*
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
||||
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
||||
|
||||
SIDDHARTA
|
||||
- HERMANN HESSE -
|
||||
|
||||
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
*/
|
||||
@ -0,0 +1,32 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project atila
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name gogo.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 slices
|
||||
|
||||
func MakeSlice[T any](size, capacity int, creator func() T) []T {
|
||||
rs := make([]T, size, capacity)
|
||||
for i := 0; i < size; i++ {
|
||||
rs[i] = creator()
|
||||
}
|
||||
return rs
|
||||
}
|
||||
Loading…
Reference in new issue