Skip to content

Instantly share code, notes, and snippets.

@sent-hil sent-hil/named_var.go
Last active Aug 29, 2015

Embed
What would you like to do?
//An experiment using `runtime/debug` package to see what info can
//be gotten in runtime.
package main
import (
"log"
"runtime/debug"
"strings"
)
type A struct {
name string
}
func (a A) Name() string {
return "Indiana Jones"
}
type B struct{}
func (b B) No(n string) {
var output = string(debug.Stack())
var newStr = strings.Split(output, "\n")
var trimmed = strings.TrimSpace(newStr[3])
var split = strings.Split(trimmed, ".")
var splitMore = split[len(split)-1]
var finally = splitMore[:len(splitMore)-1]
log.Println(output, "\n", finally)
}
func main() {
var a = A{}
B{}.No(a.Name())
}
2014/05/21 19:55:20 /Users/senthil/play/learn/go/call.go:20 (0x2046)
B.No: var output = string(debug.Stack())
/Users/senthil/play/learn/go/call.go:32 (0x2307)
main: B{}.No(a.Name())
/usr/local/Cellar/go/1.2/libexec/src/pkg/runtime/proc.c:220 (0x1466f)
main: main·main();
/usr/local/Cellar/go/1.2/libexec/src/pkg/runtime/proc.c:1394 (0x16b90)
goexit: runtime·goexit(void)
Name()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.