Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v3: user agent as client options (#659)
# Description Currently, the user agent is defined by a global variable, but this is a problem. If lego defines the user agent and an app uses exocale and lego, what will be the user agent at the end? It's not possible to know because it will depend on when and where the user agent is set: - If lego is the last to set the variable then all the calls will have the lego user agent. - If lego is the first to set the variable then all the calls will have the app user agent. - If the app and/or lego defined the user agent through another global variable, it will be "random". - if the user agent is defined inside goroutines, it will be "random". Another problem: with the global variable, if the user defines the user agent then information about the API client (versions, etc.) will be discarded, except if the user appends the previous user agent manually. Generally speaking, global variables should be avoided for a lib. --- I added a `ClientOpt` implementation to set the user agent: (`ClientOptUserAgent()`) and deprecated the global variable. I created a compatibility layer, so the usage of the global variable still works: - for a client, if the global variable `UserAgent` is overridden and `ClientOptUserAgent()` is not used, the user agent will be `UserAgent`. - for a client, if `ClientOptUserAgent()` is used, even if `UserAgent` is overridden, the user agent will be the one defined by `ClientOptUserAgent()` 2 clients can use either the `UserAgent` or `ClientOptUserAgent()`, and each client will not be impacted by the other (except if both use the global variable as before).
- Loading branch information