Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
413178e2d3
|
|||
9264a2e99b
|
@@ -258,6 +258,73 @@ func (ee *ExErr) Depth() int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMeta returns the meta value with the specified key
|
||||||
|
// this method recurses through all wrapped errors and returns the first matching meta value
|
||||||
|
func (ee *ExErr) GetMeta(key string) (any, bool) {
|
||||||
|
for curr := ee; curr != nil; curr = curr.OriginalError {
|
||||||
|
if v, ok := curr.Meta[key]; ok {
|
||||||
|
return v.Value, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
// contains test if the supplied error is contained in this error (anywhere in the chain)
|
||||||
func (ee *ExErr) contains(original *ExErr) (*ExErr, bool) {
|
func (ee *ExErr) contains(original *ExErr) (*ExErr, bool) {
|
||||||
if original == nil {
|
if original == nil {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.355"
|
const GoextVersion = "0.0.357"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2024-01-05T10:25:05+0100"
|
const GoextVersionTimestamp = "2024-01-05T10:59:06+0100"
|
||||||
|
Reference in New Issue
Block a user