Is it possible to resolve a string to function in golang without doing a manual match?
My use case is that I have a series of commands/requests represented as structs. I use reflection to present the values on the request struct to the user so that they can provide input parameters before I use the populate struct to run a query.
Some of the required values are uuids, where this is the case i would like to add a struct tag to define a function to call to populate a list of values e.g where my struct appears as follows:
type MyRequest struct{
RecordID string `uuid:"RecordIDs"`
}
I would like to reflect over the struct, read the tag so that I now have a string containing "RecordIDs" (fine up to this point) and convert this to a function call - this is the bit I'm missing.
The only way I can think of to resolve the string to a function call is to provide a map lookup, e.g
funcLookup := map[string]func() ([]string, error){}
Is there another way of doing this without providing such a map