Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateKeyword(e error) string
- func GroupErrors(errors ...error) error
- func JSON(e error, context map[string]interface{}) (string, []byte, error)
- func JSONIndent(e error, context map[string]interface{}, prefix, indent string) (string, []byte, error)
- func New(e error) error
- func NewFromStackTrace(stackTrace []string, msg string) error
- func NewFromString(msg string) error
- func NewFromStringWithAttach(msg string, attach interface{}) error
- func NewFromStringWithAttachf(format string, msg string, attach interface{}) error
- func NewFromStringWithHeader(msg string, header map[string]interface{}) error
- func NewFromStringWithHeaderf(format string, msg string, header map[string]interface{}) error
- func NewFromStringWithParam(msg string, params ...interface{}) error
- func NewFromStringf(format string, msg ...interface{}) error
- func NewWithAttach(e error, msg interface{}) error
- func NewWithHeader(e error, header map[string]interface{}) error
- func NewWithParam(e error, params ...interface{}) error
- func PrintStackFormat(flag int, file string, line int, cause string) string
- func ReGen(old error, new error) error
- func Split(s string, sub string) []string
- func Split2(s string, sub string, tmp *string, rs *[]string)
- func ToString(arg interface{}) string
- func Wrap(e error) error
- type Error
- func (e Error) BasicError() string
- func (e Error) Error() string
- func (e Error) GenerateKeyword() string
- func (e Error) GetHeader(key string) string
- func (e Error) PrintStackTrace() string
- func (e *Error) SetHeader(key string, value string)
- func (e Error) StackTrace() string
- func (e Error) StackTraceValue() string
- func (e Error) String() string
- type Reporter
- func (r *Reporter) AddModeHandler(mode string, f func(e error, context map[string]interface{})) *Reporter
- func (r *Reporter) AddURL(mode string, url string) *Reporter
- func (r Reporter) DefaultHandler(e error, context map[string]interface{})
- func (r Reporter) JSON(e error, context map[string]interface{}) (string, []byte, error)
- func (r Reporter) JSONIndent(e error, context map[string]interface{}, prefix, indent string) (string, []byte, error)
- func (r *Reporter) Mode(mode string) *Reporter
- func (r Reporter) ReportURLHandler(e error, context map[string]interface{})
- func (r Reporter) SaveError(e error, context map[string]interface{}) string
- func (r *Reporter) SetContextName(name string)
- func (r *Reporter) SetMode(mode string)
Constants ¶
const ( LcauseBy = 1 << iota LdateTime Llongfile )
Variables ¶
var DefaultHandler = func(e error, context map[string]interface{}) { var tmp = make(map[string]interface{}, 0) tmp["error_uuid"] = context["error_uuid"] delete(context, "error_uuid") tmp["message"] = Wrap(e).Error() tmp["context"] = context var buf = []byte("") var er error buf, er = json.MarshalIndent(tmp, " ", " ") if er != nil { buf = []byte(Wrap(er).Error()) } fmt.Println(string(buf)) }
It will fmt error log into console.
Functions ¶
func JSONIndent ¶
func NewFromStackTrace ¶
new an error with existed stacktrace and generate the new error with new msg
func NewFromStringWithAttach ¶
new an error from string with header
func NewFromStringWithAttachf ¶
new an error from well format string with header
func NewFromStringWithHeader ¶
new an error from string with header
func NewFromStringWithHeaderf ¶
new a error from a well format string with header
func NewFromStringWithParam ¶
func NewFromStringf ¶
new a error from a well format string
func NewWithAttach ¶
func NewWithHeader ¶
New an error with header info
func NewWithParam ¶
new a error from a error with numeric params
Types ¶
type Error ¶
type Error struct { // basic E error StackTraces []string // do not use context, it's tracking bug on development Context map[string]interface{} Header map[string][]string // upper ReGenerated bool Errors []error Flag int Keyword string }
an Error instance wraps an official error and storage its stackTrace. E and StackTraces work for the basic server When tries to wrap the origin error to another, logic does like:
if er := f(); er!=nil{ log.Println(er.Error()) return errors.New("inner service error") }
'ReGenerated' should be set true and different errors should be saved in 'Errors',and the 'stackTrace' should include all stackTraces above.But in this case,'Error.E' only point to the origin one It's ok to storage both official error and 'Error'
func (Error) BasicError ¶
func (Error) GenerateKeyword ¶
generate an error key word. key word is used to help save errors in database It's suggested to set unique(date, keyword), when error with same keyword in a day,database only saves field 'times' rather than another error record
func (Error) PrintStackTrace ¶
print error stack trace e.Flag only controls 'Error' type or official error which has been wrapped to 'Error'. e.Flag only controls stack trace inner an Error type ,rather than some stack trace which has been init by api NewFromStackTrace([]string,string)
func (*Error) SetHeader ¶
set header for an error obj SetHeader is safe whether e.Header is nil or not
func (Error) StackTraceValue ¶
type Reporter ¶
type Reporter struct { Url map[string]string HandleMode map[string]func(e error, context map[string]interface{}) // contains filtered or unexported fields }
func NewReporter ¶
func (*Reporter) AddModeHandler ¶
func (Reporter) DefaultHandler ¶
func (Reporter) JSONIndent ¶
func (*Reporter) Mode ¶
Mode will clone a copy of reporter to avoid different goroutine using a unsafe clone
func (Reporter) ReportURLHandler ¶
rp.Mode related, should call like rp.Mode("dev").ReportURLHandler It will post error with context to an url storaged in reporter.Url