github.com/laof/lite-speed-test@v0.0.0-20230930011949-1f39b7037845/common/error.go (about) 1 package common 2 3 import ( 4 "fmt" 5 ) 6 7 type Error struct { 8 info string 9 } 10 11 func (e *Error) Error() string { 12 return e.info 13 } 14 15 func (e *Error) String() string { 16 return e.info 17 } 18 19 func (e *Error) Base(err error) *Error { 20 if err != nil { 21 e.info += " | " + err.Error() 22 } 23 return e 24 } 25 26 func NewError(info string) *Error { 27 return &Error{ 28 info: info, 29 } 30 } 31 32 func Must(err error) { 33 if err != nil { 34 fmt.Println(err) 35 panic(err) 36 } 37 } 38 39 func Must2(_ interface{}, err error) { 40 if err != nil { 41 fmt.Println(err) 42 panic(err) 43 } 44 }