Skip to content
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

Refactoring usages of http.client #454

Open
Alex-CD opened this issue Oct 6, 2024 · 3 comments
Open

Refactoring usages of http.client #454

Alex-CD opened this issue Oct 6, 2024 · 3 comments

Comments

@Alex-CD
Copy link
Contributor

Alex-CD commented Oct 6, 2024

Hey :)

So a few places depend on Go's built-in http.client directly, or indirectly (through httpclient.go).
My thought was that it could be an improvement to work towards injecting http.client as a dependency - this would decouple several functions away from it, improving their testability.

As an initial first step, I could make a change that:

  • Refactors httpclient.SendRequest to accept a *http.client parameter.
  • In usages of httpclient.SendRequest, have them construct a *http.client to inject using httpClient.GetHttpClient
  • Create some unit tests for httpclient.SendRequest.

Of course, usages http.SendRequest would still depend indirectly on http.client ( via httpClient.GetHttpClient), but this would get us a foot in the door regarding doing more dependency injection elsewhere.
I've seen some other issues that discuss how heavily coupled some functions are, and I believe dependency injection could help us improve some of those tight coupling problems

This would be my first open source contribution in a while, and my first Go work in a few years, so your thoughts are especially welcome here :)

My team have also been making heavy use of this tool for a while and it's been really helpful, so thank you! ❤️

@gregorriegler
Copy link
Collaborator

I like the Idea!
Can you PR an example so i got the full picture?

@Alex-CD
Copy link
Contributor Author

Alex-CD commented Oct 6, 2024

Will get one with you soon!

@Alex-CD
Copy link
Contributor Author

Alex-CD commented Oct 10, 2024

#457

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants