mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
improve middleware feature for ghttp.Server
This commit is contained in:
@ -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:]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user