Created
July 15, 2016 06:48
-
-
Save shicky/041aa613a0754d0e355c53c4989e1bb9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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() { | |
// register method | |
tasks := make(map[string]interface{}) | |
tasks["add"] = add | |
// retrieve and run | |
task := tasks["add"] | |
f := reflect.ValueOf(task) | |
// number of arguments supported by func | |
numArgs := f.Type().NumIn() | |
log.Printf("Num Args: %d\n", numArgs) | |
// construct arguments | |
params := []interface{}{44545, 853905} | |
log.Printf("Num Param: %d\n", params) | |
// convert arguments to reflect | |
in := make([]reflect.Value, len(params)) | |
for k, param := range params { | |
in[k] = reflect.ValueOf(param) | |
} | |
res := f.Call(in) | |
log.Println(res[0]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment