-
Notifications
You must be signed in to change notification settings - Fork 6k
Rewrite of Go client. #4440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite of Go client. #4440
Conversation
- Removed go-resty - Moved http.Client to APIClient structure (for keep-alive, http2 multiplexing). - Authentication through contexts - Able to pass custom http.Clients (caching across clusters, custom timeouts, rate limiting, tracing). - Catches http errors - Optional parameters via map[string]interface - Documentation updated - Examples in README.md
Add optional parameters to go client using map[string]interface{} (#4…
# Conflicts: # modules/swagger-codegen/src/main/resources/go/api.mustache # modules/swagger-codegen/src/main/resources/go/api_doc.mustache # samples/client/petstore/go/go-petstore/docs/FakeApi.md # samples/client/petstore/go/go-petstore/docs/PetApi.md # samples/client/petstore/go/go-petstore/docs/StoreApi.md # samples/client/petstore/go/go-petstore/docs/UserApi.md # samples/client/petstore/go/go-petstore/fake_api.go # samples/client/petstore/go/go-petstore/pet_api.go # samples/client/petstore/go/go-petstore/store_api.go # samples/client/petstore/go/go-petstore/user_api.go # samples/client/petstore/go/pet_api_test.go
|
Hmm. so the test environment is going to need golang.org/x/oauth2 and golang.org/x/context. Context is now a standard lib in Go 1.7 but i use the old path for compatibility with Go 1.6 Perhaps the script can go The tests pass locally, I also have it in production using oauth2. |
|
@antihax thanks for the PR. The CI failure with Appveyor can be ignored. |
|
@wy-z can you please also review this particular change? Your feedback is much appreciated. |
|
It seems that go-githubgodo |
|
@wy-z yes, that's one way to do it. For API clients in other languages (e.g. Python, Ruby, PHP, C#), there's a |
|
I am still learning go, but this is my understanding so far. If I am off base, let me know. Go is not really a client, it is a pool of connections that get reused with requests multiplexed (http2) over the same connection at the same time with idle connections reused rather than opening new ones. So in the scenario I have, we can (plan to) have upwards of 30,000 oauth tokens which I need to pull API calls on concurrently. Feeding the token in the request seems like the most optimal design since it is a request header, and we have stateful requests/response. If we attach the token to the client, we would be forced to create/destroy 30,000 and clients. If we offer provisions to change the token, we will have to do so with a mutex to prevent racing on the token through the request and lower our concurrency. For example, this is what I have in production. |
|
There's an issue here if the spec defines multiple security definitions wrt OAuth2. This generates endpoints like this: func (a PublicApiService) Get(ctx context.Context, ctx context.Context, param string) (SomeResponse, *http.Response, error) {} |
|
I love that this now accepts http.Clients, but I'm not sold on using Context.context for passing tokens. This article has some counter-arguments. Never seen a Go SDK take this approach. |
|
I am rewriting this over the weekend hopefully and can resolve the double ctx issue. I am going back to the config with one TokenSource default and then offer a .WithOAuth(tokenSource).Operation() to allow tokens per request for those who need it. The reasoning with ctx is that you can pass various types of authentication or none at all. Again much of this comes about because I needed request based tokens, instead of tokens tied to a client. I have run into a number of other issues since this PR... No Date format in Go, another issue around []int in returns, etc. |
|
So I am unfortunately back to contexts again... chained functions are not safe. https://play.golang.org/p/YepaybwrJH If anyone has any other suggestions let me know. My original problem is that is i have one APIClient, ~200 concurrent workers running operations, and 200+ TokenSource's for OAuth2. I would like this to function concurrently without a mutex or running multiple APIClients. |
|
From a first look-through, this seems to solve the |
|
Closed via #5037 |
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0branch for breaking (non-backward compatible) changes.Description of the PR
Rewrite of Go client. This will need community review. This is modeled after some other API clients (go-github, godo, etc).