[Solved] Go http client setup for multiple endpoints?


Disclaimer: this is not a direct answer to your question but rather an attempt to direct you to a proper way of solving your problem.

  • Try to avoid a singleton pattern for you MyApp. In addition, New is misleading, it doesn’t actually create a new object every time. Instead you could be creating a new instance every time, while preserving the http client connection.
  • Don’t use constructions like this: AppCon == (MyApp{}), one day you will shoot in your leg doing this. Use instead a pointer and compare it to nil.
  • Avoid race conditions. In your code you start a goroutine and immediately proceed to the new iteration of the for loop. Considering you re-use the whole MyApp instance, you essentially introduce a race condition.
  • Using cookies, you make your connection kinda stateful, but your task seems to require stateless connections. There might be something wrong in such an approach.

solved Go http client setup for multiple endpoints?