gopkg.in/goose.v2@v2.0.1/testservices/hook/service_gc.go (about)

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