Created
July 22, 2018 07:03
-
-
Save u2386/18e890953185f451b75c7a5ec03c1a98 to your computer and use it in GitHub Desktop.
Dynamic go function using reflect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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