improve middleware feature for ghttp.Server

This commit is contained in:
John
2019-12-04 10:03:03 +08:00
parent 890865251b
commit a06ca31530
14 changed files with 300 additions and 185 deletions

View File

@ -11,6 +11,7 @@ import (
"bytes"
"fmt"
"path/filepath"
"reflect"
"runtime"
"strconv"
"strings"
@ -244,3 +245,21 @@ func CallerFileLineShort() string {
_, path, line := Caller()
return fmt.Sprintf(`%s:%d`, filepath.Base(path), line)
}
// FuncPath returns the complete function path of given <f>.
func FuncPath(f interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
}
// FuncName returns the function name of given <f>.
func FuncName(f interface{}) string {
path := FuncPath(f)
if path == "" {
return ""
}
index := strings.LastIndexByte(path, '/')
if index < 0 {
index = strings.LastIndexByte(path, '\\')
}
return path[index+1:]
}