Go map of functions

前端 未结 6 1531
春和景丽
春和景丽 2020-12-23 09:21

I have Go program that has a function defined. I also have a map that should have a key for each function. How can I do that?

I have tried this, but this doesn\'t wo

6条回答
  •  爱一瞬间的悲伤
    2020-12-23 10:03

    m := map[string]func(string, string)
    

    Works if you know the signature (and all the funcs have the same signature) I think this is cleaner/safer than using interface{}

提交回复
热议问题