1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

fix #2158 and more

This commit is contained in:
Gerasimos (Makis) Maropoulos
2023-07-08 02:08:18 +03:00
parent 757e7fe61b
commit 6add1ba49b
79 changed files with 551 additions and 467 deletions

View File

@@ -6,9 +6,7 @@ import (
"net/http"
"os"
"path"
"path/filepath"
"reflect"
"runtime"
"strings"
"time"
@@ -722,7 +720,7 @@ func (api *APIBuilder) createRoutes(errorCode int, methods []string, relativePat
}
}
filename, line := getCaller()
filename, line := hero.GetCaller()
fullpath := api.relativePath + relativePath // for now, keep the last "/" if any, "/xyz/"
if len(handlers) == 0 {
@@ -1706,50 +1704,3 @@ func (api *APIBuilder) Layout(tmplLayoutFile string) Party {
return api
}
// https://golang.org/doc/go1.9#callersframes
func getCaller() (string, int) {
var pcs [32]uintptr
n := runtime.Callers(1, pcs[:])
frames := runtime.CallersFrames(pcs[:n])
wd, _ := os.Getwd()
var (
frame runtime.Frame
more = true
)
for {
if !more {
break
}
frame, more = frames.Next()
file := filepath.ToSlash(frame.File)
// fmt.Printf("%s:%d | %s\n", file, frame.Line, frame.Function)
if strings.Contains(file, "go/src/runtime/") {
continue
}
if !strings.Contains(file, "_test.go") {
if strings.Contains(file, "/kataras/iris") &&
!strings.Contains(file, "kataras/iris/_examples") &&
!strings.Contains(file, "kataras/iris/middleware") &&
!strings.Contains(file, "iris-contrib/examples") {
continue
}
}
if relFile, err := filepath.Rel(wd, file); err == nil {
if !strings.HasPrefix(relFile, "..") {
// Only if it's relative to this path, not parent.
file = "./" + filepath.ToSlash(relFile)
}
}
return file, frame.Line
}
return "???", 0
}