nightingale/vendor/github.com/toolkits/pkg/errors/errors.go

37 lines
501 B
Go
Raw Normal View History

2020-09-26 17:02:52 +08:00
package errors
import (
"fmt"
)
type PageError struct {
Message string
}
func (p PageError) Error() string {
return p.Message
}
func (p PageError) String() string {
return p.Message
}
func Bomb(format string, a ...interface{}) {
panic(PageError{Message: fmt.Sprintf(format, a...)})
}
func Dangerous(v interface{}) {
if v == nil {
return
}
switch t := v.(type) {
case string:
if t != "" {
panic(PageError{Message: t})
}
case error:
panic(PageError{Message: t.Error()})
}
}