I am a beginner in Go. I maybe thinking too traditional coming from years in other languages, but here is what I want to do in Go. Assume the following use case
- I have interface I. This interface has functions, start() and stop()
- There are many structs implementing the interface. struct A, struct B, struct C
- When the application starts, I want to call start() on structs A, B and C
- Similarly, when the application terminates, I want to call stop() on the A, B, C structs.
- I do not want to hard code struct A, B and C anywhere in the code to call the start/stop functions. This is so that when I add struct D later (also implements interface I), the code will automatically work without modification.
- In order to achieve this, I need to be able to say "Hey Go, give me all the types that implement interface I".
- If I get back a slice of A, B and C, I can simply loop through and call the right methods at the right time.
Doable in Go?