1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
// +build !gccgo
package hook
import (
"runtime"
"strings"
)
// currentServiceMethodName returns the method executing on the service when ProcessControlHook was invoked.
func (s *TestService) currentServiceMethodName() string {
pc, _, _, ok := runtime.Caller(2)
if !ok {
panic("current method name cannot be found")
}
return unqualifiedMethodName(pc)
}
func unqualifiedMethodName(pc uintptr) string {
f := runtime.FuncForPC(pc)
fullName := f.Name()
nameParts := strings.Split(fullName, ".")
return nameParts[len(nameParts)-1]
}
|