Hi team,
I am trying to read data from database from golang.I have two different structs and my function returns these two different structs for same code.
How can i made it generic.
type EventConfigDbDocs struct {
Docs []EventConfiguration json:"docs"
}
type EventDataDbDocs struct {
Docs []Event json:"docs"
}
I don’t yet understand what you are trying to do. Can you show the function that returns either of these types? I see getEventConfig in your original post, but that only returns []entities.EventConfiguration. Are you saying that getEventConfig can also return []entities.Events? If so, then I would like to see how the code knows what type to return.
loadQueryResults (or if you have a better name, of course go with that)
getEventData
getEventConfig
loadQueryResults should probably look exactly like your current getEventConfig but the eventResults passed in to Find on line 14 should become a parameter to the function: