github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/pkg/plugins/errors.go (about) 1 package plugins // import "github.com/demonoid81/moby/pkg/plugins" 2 3 import ( 4 "fmt" 5 "net/http" 6 ) 7 8 type statusError struct { 9 status int 10 method string 11 err string 12 } 13 14 // Error returns a formatted string for this error type 15 func (e *statusError) Error() string { 16 return fmt.Sprintf("%s: %v", e.method, e.err) 17 } 18 19 // IsNotFound indicates if the passed in error is from an http.StatusNotFound from the plugin 20 func IsNotFound(err error) bool { 21 return isStatusError(err, http.StatusNotFound) 22 } 23 24 func isStatusError(err error, status int) bool { 25 if err == nil { 26 return false 27 } 28 e, ok := err.(*statusError) 29 if !ok { 30 return false 31 } 32 return e.status == status 33 }