Invoke golang



package main

import (
	"fmt"
	"reflect"
)

var funcMap = map[string]interface{}{
	"Hello": Hello,
}

func Hello(name string) {
	fmt.Printf("Hello, %s!\n", name)
}

func main() {
	nameFunc := "Hello"

	if fn, ok := funcMap[nameFunc]; ok {
		funcValue := reflect.ValueOf(fn)
		args := []reflect.Value{reflect.ValueOf("Gopher")}
		funcValue.Call(args)
	} else {
		fmt.Println("Function not found!")
	}
}


Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *

Можно использовать следующие HTML-теги и атрибуты: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>