I have several methods that I call for some cases (e.g. Add, Delete, etc.). However, over time, the number of cases increases, and my switch cabinet becomes longer. Therefore, I decided to create a method map, for example, Go to the function map ; here the mapping of functions is trivial. However, is it possible to create a method map in Go?
When we have a method:
func (f *Foo) Add(a string, b int) { }
The syntax below creates a compile-time error:
actions := map[string]func(a, b){ "add": f.Add(a,b), }
Can I create a method map in Go?
source share