diff --git a/exerr/exerr.go b/exerr/exerr.go index 01855d2..cc1c34b 100644 --- a/exerr/exerr.go +++ b/exerr/exerr.go @@ -270,6 +270,61 @@ func (ee *ExErr) GetMeta(key string) (any, bool) { return nil, false } +// GetMetaString functions the same as GetMeta, but returns false if the type does not match +func (ee *ExErr) GetMetaString(key string) (string, bool) { + if v1, ok := ee.GetMeta(key); ok { + if v2, ok := v1.(string); ok { + return v2, true + } + } + return "", false +} + +func (ee *ExErr) GetMetaBool(key string) (bool, bool) { + if v1, ok := ee.GetMeta(key); ok { + if v2, ok := v1.(bool); ok { + return v2, true + } + } + return false, false +} + +func (ee *ExErr) GetMetaInt(key string) (int, bool) { + if v1, ok := ee.GetMeta(key); ok { + if v2, ok := v1.(int); ok { + return v2, true + } + } + return 0, false +} + +func (ee *ExErr) GetMetaFloat32(key string) (float32, bool) { + if v1, ok := ee.GetMeta(key); ok { + if v2, ok := v1.(float32); ok { + return v2, true + } + } + return 0, false +} + +func (ee *ExErr) GetMetaFloat64(key string) (float64, bool) { + if v1, ok := ee.GetMeta(key); ok { + if v2, ok := v1.(float64); ok { + return v2, true + } + } + return 0, false +} + +func (ee *ExErr) GetMetaTime(key string) (time.Time, bool) { + if v1, ok := ee.GetMeta(key); ok { + if v2, ok := v1.(time.Time); ok { + return v2, true + } + } + return time.Time{}, false +} + // contains test if the supplied error is contained in this error (anywhere in the chain) func (ee *ExErr) contains(original *ExErr) (*ExErr, bool) { if original == nil { diff --git a/goextVersion.go b/goextVersion.go index c0a20c4..4ebf68b 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.356" +const GoextVersion = "0.0.357" -const GoextVersionTimestamp = "2024-01-05T10:43:39+0100" +const GoextVersionTimestamp = "2024-01-05T10:59:06+0100"