Skip to content

Instantly share code, notes, and snippets.

@u2386
Created July 22, 2018 07:03
Show Gist options
  • Save u2386/18e890953185f451b75c7a5ec03c1a98 to your computer and use it in GitHub Desktop.
Save u2386/18e890953185f451b75c7a5ec03c1a98 to your computer and use it in GitHub Desktop.
Dynamic go function using reflect
package main
import (
"fmt"
"reflect"
)
func main() {
a := func(){fmt.Println("aaa")}
a()
v := reflect.ValueOf(&a)
b := func(){fmt.Println("bbb")}
vb := reflect.ValueOf(&b)
v.Elem().Set(vb.Elem())
a()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment