Closed billypap1 closed 6 months ago
Global variables are not a good design and are prone to abuse. Imagine a scenario :
SetTimeout(5 * time. Second)
SetTimeout(500 * time. Second)
SkipSSL(true)
SkipSSL(false)
This can easily create conflicts, and very difficult to manage and troubleshoot bugs.
If you want to use a global variable, you can define this global variable within your app, limited to your own app
@ahuigo Thanks for responding to a comment.
@billypap1 It is recommended to create a resty client per destination Host with respective settings for the usage.
client1 := resty.New().SetBaseURL("http://localohost1")
....
client2 := resty.New().SetBaseURL("http://localohost2")
...
I use resty in my Golang app to call external APIs. Is it better to have it as a global variable or create it each time I need to call an external API?
My code bellow:
Will there be any issue with concurrent external API calls?