Hi,
I’m new to Golang so sorry if I say or write something completely off
I’m trying to run functions as jobs and I store function names in DB and then try to run them as Cronjob, and it works till point where it needs to execute.
So I tried to map them:
var funcs = map[string]func() {"countRegistrations":countRegistrations}
and then execute it with:
funcs["\""+name+"\""]()
Where name is retrieved from DB
but this throws memory error panic.
I also figured that this is not flexible since I can add new job (func name in DB) but for the mapping I have to restart DB.
Is there a way to call the function which name is stored in the variable name?
Hey, thanks for tips, I think i tried without quotes and it was nil, but it might be possible that it was nil cause of db fetching problems i had previous, I’ll try.
As for the job to update map, indeed a good option, i already have it that is fetching them from db, forgot that i can update map also
The idea was to have a job picking up new records from DB, that don’t have jobId updated, so funName field was just string (varchar) name of the function I want to run from that main job (as another job and then have that function run as separate job). So it would allow me to add more jobs dynamically.
I first tried to invoke funName just like that but got: ./main.go:137:4: funName (variable of type string) is not used
so that lead me to that funcs map that have literal string mapped to func name, it works now when I have hardcoded string and name in that map