github.com/searKing/golang/go@v1.2.117/errors/wrap.go (about) 1 // Copyright 2023 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package errors 6 7 import ( 8 "errors" 9 ) 10 11 // IsAny reports whether any error in err's tree matches any target in targets. 12 func IsAny(err error, targets ...error) bool { 13 if len(targets) == 0 { 14 // Avoid scanning all targets. 15 return false 16 } 17 for _, target := range targets { 18 if errors.Is(err, target) { 19 return true 20 } 21 } 22 return false 23 } 24 25 // IsAll reports whether any error in err's tree matches all target in targets. 26 func IsAll(err error, targets ...error) bool { 27 if len(targets) == 0 { 28 return false 29 } 30 for _, target := range targets { 31 if !errors.Is(err, target) { 32 // Avoid scanning all targets. 33 return false 34 } 35 } 36 return true 37 }