Skip to content

Commit

Permalink
middleware.Recoverer, a bit prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Mar 24, 2020
1 parent f185085 commit fc7c9bb
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions middleware/recoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func (s prettyStack) parse(debugStack []byte, rvr interface{}) ([]byte, error) {
useColor := true
buf := &bytes.Buffer{}

cW(buf, useColor, bBlue, "\n>>")
cW(buf, useColor, bRed, " panic: ")
cW(buf, useColor, bMagenta, "%v", rvr)
cW(buf, useColor, bBlue, " <<\n\n")
cW(buf, false, bRed, "\n")
cW(buf, useColor, bCyan, " panic: ")
cW(buf, useColor, bBlue, "%v", rvr)
cW(buf, false, bWhite, "\n \n")

// process debug stack info
stack := strings.Split(string(debugStack), "\n")
Expand All @@ -78,10 +78,6 @@ func (s prettyStack) parse(debugStack []byte, rvr interface{}) ([]byte, error) {
}
}

if strings.HasPrefix(stack[0], "goroutine") {
cW(buf, useColor, bCyan, "%s\n\n", stack[0])
}

// reverse
for i := len(lines)/2 - 1; i >= 0; i-- {
opp := len(lines) - 1 - i
Expand Down Expand Up @@ -182,15 +178,15 @@ func (s prettyStack) decorateSourceLine(line string, useColor bool, num int) (st
fileColor = bRed
lineColor = bMagenta
} else {
cW(buf, useColor, bWhite, " ")
cW(buf, false, bWhite, " ")
}
cW(buf, useColor, bWhite, "%s", dir)
cW(buf, useColor, fileColor, "%s", file)
cW(buf, useColor, lineColor, "%s", lineno)
if num == 1 {
cW(buf, useColor, bRed, "\n")
cW(buf, false, bWhite, "\n")
}
cW(buf, useColor, bWhite, "\n")
cW(buf, false, bWhite, "\n")

return buf.String(), nil
}

0 comments on commit fc7c9bb

Please sign in to comment.