Invoke a function which is received as an interface variable in golang
<p>I have a code which is similar to the following</p>

<pre><code>package main

import "fmt"

func PrintThis(arg string) {
    fmt.Printf("I'm printing %s", arg)
}

func PrintThisAndThat(arg1, arg2 string) {
    fmt.Printf("Now printing %s and %s", arg1, arg2)
}

func Invoke(fn interface{}, args ...string) {
    //fn(args...)
}

func main() {
    Invoke(PrintThis, "foo")
    Invoke(PrintThisAndThat, "foo", "bar")
}
</code></pre>

<p>This is not the actual production code, but this is a simplified version.</p>

<p>Question :- If I uncomment the line <code>//fn(args...)</code> I get a compile error <code>prog.go:14: cannot call non-function fn (type interface {})</code></p>

<p>How do I execute the function which is received as the argument tho the Invoke() function? </p>

<p>What is the right way to achieve this?</p>