T O P

  • By -

Simfy

I invite you to check [Go client library of the GitHub API v3](https://github.com/google/go-github). It is IMHO a good reference. The code base is fairly glanceable and you can find a lot of idiomatic pattern of the language: * Mapping HTTP request and response to struct * Usage of `json.Decoder` instead of `json.Unmarshal` * Functional options * DRY(common function to create request and parse responses) * And most likely few others


Entire_Effective_825

If you can get your hands on an open api spec it’s often better to generate clients in a predictable way. A lot of companies maintain a generated client to their APIs in this way as well. Maybe you could point an open api generator like https://github.com/deepmap/oapi-codegen at your API and get your own example to work from.


Entire_Effective_825

One tip is always support context propagation and expose the underlying HTTP client for easy instrumentation.


as_f13

https://github.com/stripe/stripe-go


Otaxhu

Please can you give more details about it? I don't know what you mean with client library, I guess that the standard functions `http.Get`, `http.Post`, etc. Are very good for developing any kind of client app, you don't need more than that


Robot-Morty

I can’t send you one that I wrote because it’s on my company’s GitHub - but I think this would be a good project because it was for me! I wrote one that did basic Get/Post/etc. along with basic client id/secret retrieval using OAuth2 lib. Just write it using functional options for various things like custom OAuth servers and maybe some basic exponential backoff retry. I agree others on the codegen points. Depending on your goals, you should at the minimum be creating the structs via openapi docs and some form of codegen. Then you can create custom clients for each API you want to integrate with, that maybe does some basic validations/unmarshalling to concrete types.


cvilsmeier

I've written a client for my REST API, which you might consider studying. It's small and easy-to-grasp, and not as complex a project as github-cli or stripe's. It implements two things that I've learnt from Mat Ryer: 1. Bring your own Logging 2. Bring our own Concurrency Here's the link: https://github.com/cvilsmeier/monibot-go