~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/gopkg.in/goose.v1/testservices/hook/service_gc.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}