http, websocket api handler 추가
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
)
|
||||
@ -101,3 +102,44 @@ func Panicln(v ...interface{}) {
|
||||
errlogger.Output(2, string(debug.Stack()))
|
||||
panic(s)
|
||||
}
|
||||
|
||||
type errWithCallstack struct {
|
||||
inner error
|
||||
frames []*runtime.Frame
|
||||
}
|
||||
|
||||
func (ecs *errWithCallstack) Error() string {
|
||||
if ecs.frames == nil {
|
||||
return ecs.inner.Error()
|
||||
}
|
||||
|
||||
out := make([]string, 0, len(ecs.frames)+1)
|
||||
out = append(out, ecs.inner.Error())
|
||||
for i := len(ecs.frames) - 1; i >= 0; i-- {
|
||||
frame := ecs.frames[i]
|
||||
out = append(out, fmt.Sprintf("%s\n\t%s:%d", frame.Function, frame.File, frame.Line))
|
||||
}
|
||||
|
||||
return strings.Join(out, "\n")
|
||||
}
|
||||
|
||||
func ErrorWithCallStack(err error) error {
|
||||
var frames []*runtime.Frame
|
||||
|
||||
if recur, ok := err.(*errWithCallstack); ok {
|
||||
err = recur.inner
|
||||
frames = recur.frames
|
||||
}
|
||||
|
||||
pc, _, _, ok := runtime.Caller(1)
|
||||
if ok {
|
||||
curframes := runtime.CallersFrames([]uintptr{pc})
|
||||
f, _ := curframes.Next()
|
||||
frames = append(frames, &f)
|
||||
}
|
||||
|
||||
return &errWithCallstack{
|
||||
inner: err,
|
||||
frames: frames,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user