0

How can I check the identify of a function in Go?

Suppose some code like this:

myCallback := func() { /* Do something */ }
someObject.Callback = myCallback;

// Then sometime later..

/* Has my callback been changed? */

if someObject.Callback != myCallback {
    log.Fatal("Someone changed my callback and didn't ask my permission!\n")
}

Of course, this specific code doesn't work. It complains that func can only be compared to nil.

So is there another way to do a function comparison to see if two functions (or function references--is that a thing in Go?) are the same?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

0 Answers0