Go map of functions -


i have go program has function defined. have map should have key each function. how can that?

i have tried this, doesn't work.

 func a(param string) {  }  m := map[string] func {     'a_func': a, }  key, value := range m {    if key == 'a_func' {     value(param)     } } 

are trying this? i've revised example use varying types , numbers of function parameters.

package main  import "fmt"  func f(p string) {     fmt.println("function f parameter:", p) }  func g(p string, q int) {     fmt.println("function g parameters:", p, q) }  func main() {     m := map[string]interface{}{         "f": f,         "g": g,     }     k, v := range m {         switch k {         case "f":             v.(func(string))("astring")         case "g":             v.(func(string, int))("astring", 42)         }     } } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -