package main import ( "errors" "fmt" ) type errorCreateVolume struct { s string } func NewErrorCreateVolume(text string) error { return errorCreateVolume{text} } func (e errorCreateVolume) Error() string { return e.s } func IsErrorCreateVolume(err error) bool { var myErr errorCreateVolume if errors.As(err, &myErr) { return true } return false } func main() { err := NewErrorCreateVolume("create") err1 := errors.New("ceshi") if IsErrorCreateVolume(err) { fmt.Println("shi") } if !IsErrorCreateVolume(err1) { fmt.Println("bu shi") } }
标签:return,err,自定义,IsErrorCreateVolume,func,error,类型,errorCreateVolume From: https://www.cnblogs.com/zxqblogrecord/p/18157631