File: service_gc.go

package info (click to toggle)
golang-gopkg-goose.v1 0.0~git20170406.3228e4f-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,116 kB
  • sloc: python: 160; makefile: 3
file content (24 lines) | stat: -rw-r--r-- 544 bytes parent folder | download | duplicates (2)
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]
}