This question already has an answer here:
Let's say we have a code like this:
package main
import "fmt"
type Parent struct{}
func (p Parent) WhoCalledMe() string {
// return the name of instance who called this method, Parent or Child
}
type Child struct {
Parent
}
func main() {
child := Child{}
parent := Parent{}
fmt.Println(child.WhoCalledMe()) // return Child
fmt.Println(parent.WhoCalledMe()) // return Parent
}
Is it possible to get the name or type of instance who called the WhoCalledMe
method?
</div>