How to change the function name of string type to func type in golang

when calling a function, how should I change the function name to a parameter of type func if the function name is a string?

func test1 () {

fmt.Println("hello")

}

func addFunc (cmd func ()) {

fmt.Println(cmd)

}

/ / function name read dynamically from configuration
funcname: = "test1"

/ / add the function to execute
addFunc (funcname)

error: cannot use funcname (type string) as type func () in argument to addFunc

Aug.23,2021

use a map [string] func ()
to dynamically read funcname, find func () in map

Menu