This is a creation in Article, where the information may have evolved or changed.
In code programming, calling a function that matches a name in a method is very effective
The reflection mechanism of go can be used to realize
Import("Errors" "FMT" "Reflect")funcFoor () {fmt. Println ("Start->foor ()")}funcSay (numberint) {FMT. Printf ("This text is%d", number)}funcCall (MMap[string]Interface{}, NamestringParams...Interface{}) (Result []reflect. Value, err Error) {f: = reflect. ValueOf (M[name])if Len(params)! = F.type (). Numin () {err = errors. New ("The number of the params is not adapted.")return} In: = Make([]reflect. Value,Len(params)) forK, param: =Rangeparams {in[k] = reflect. ValueOf (param)} result = F.call (in)return}funcMain () {FMT. Println ("Start Main func ()")//Map direct call functionFuncs: =Map[string]func(){"Foor": Foor} funcs["Foor"]()//ReflectionXfuncs: =Map[string]Interface{}{"Say": Say} call (Xfuncs,"Say",123)}//Output//Start->foor ()//This text is 123