Is theere a way to use a string as a function name and call it?
I have a map of strings to function namesstuff := map[string]string{'keyword','function'}
and when the keyword
is used, i want to call function
with 2 argumentsstuff['keyword'](arg1,arg2)
But it gives me this error:
cannot call non-function key (type string)
Is there a way to keep my string
to string
map and still achieve this?
The map you're using isn't syntactically valid. You probably want something like this:
stuff := map[string]func(string, string)
You would then be able to use your string key to pull out a function from the map and call it:
stuff["keyword"]("foo", "goo")