2 Star 8 Fork 6

user_499098 / imgproxy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
errors.go 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"fmt"
"runtime"
"strings"
)
type imgproxyError struct {
StatusCode int
Message string
PublicMessage string
Unexpected bool
stack []uintptr
}
func (e *imgproxyError) Error() string {
return e.Message
}
func (e *imgproxyError) FormatStack() string {
if e.stack == nil {
return ""
}
return formatStack(e.stack)
}
func (e *imgproxyError) StackTrace() []uintptr {
return e.stack
}
func (e *imgproxyError) SetUnexpected(u bool) *imgproxyError {
e.Unexpected = u
return e
}
func newError(status int, msg string, pub string) *imgproxyError {
return &imgproxyError{
StatusCode: status,
Message: msg,
PublicMessage: pub,
}
}
func newUnexpectedError(msg string, skip int) *imgproxyError {
return &imgproxyError{
StatusCode: 500,
Message: msg,
PublicMessage: "Internal error",
Unexpected: true,
stack: callers(skip + 3),
}
}
func callers(skip int) []uintptr {
stack := make([]uintptr, 10)
n := runtime.Callers(skip, stack)
return stack[:n]
}
func formatStack(stack []uintptr) string {
lines := make([]string, len(stack))
for i, pc := range stack {
f := runtime.FuncForPC(pc)
file, line := f.FileLine(pc)
lines[i] = fmt.Sprintf("%s:%d %s", file, line, f.Name())
}
return strings.Join(lines, "\n")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yunwisdoms/imgproxy.git
git@gitee.com:yunwisdoms/imgproxy.git
yunwisdoms
imgproxy
imgproxy
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891