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

Discovery: HTTP client for communicating with Discovery Service #2711

Merged
merged 5 commits into from
Jan 9, 2024

Conversation

reinkrul
Copy link
Member

@reinkrul reinkrul commented Jan 5, 2024

No description provided.

Copy link
Member

@woutslakhorst woutslakhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just small stuff

discovery/api/v1/model/types.go Show resolved Hide resolved
)

// Invoker is the interface for the client that invokes the remote Discovery Service.
type Invoker interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the interface? Do you expect to mock it for other tests? Most http clients are just structs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does eliminate the service implementation (signatures for a service struct would be the same)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I mocked it in tests. The simple function signatures of the interface makes it mocking easier (over having to spin up an actual HTTP client or mocking the HTTP calls).

discovery/api/v1/client/http.go Outdated Show resolved Hide resolved
if err != nil {
return nil, nil, fmt.Errorf("failed to invoke remote Discovery Service (url=%s): %w", serviceEndpointURL, err)
}
defer httpResponse.Body.Close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed when a ReadAll is done?

Copy link
Member Author

@reinkrul reinkrul Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case ReadAll() fails. But then, the connection might not be reused anyways;

        ... It is the caller's responsibility to
	// close Body. The default HTTP client's Transport may not
	// reuse HTTP/1.x "keep-alive" TCP connections if the Body is
	// not read to completion and closed.

I tend to always make sure I close external resources, what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might panic

@reinkrul reinkrul requested a review from woutslakhorst January 8, 2024 10:02
Copy link
Member

@gerardsn gerardsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no real issues, just warming up the brains again

}
}

var _ Invoker = &HTTPInvoker{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have 8 HTTPClients in the other APIs. Is there a reason to deviate from our own convention here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to have an interface, which shouldn't be named Client since it's already in a package named client. Naming it HTTPClient makes naming the implementation hard, since it would be something like DefaultHTTPClient. But I guess that's the least of all evils, although it includes the package name. But consistency is probably the most important here (again).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DefaultHTTPClient could also be httpClient. IDEs will complain about returning an unexported type from an exported function, but it works just fine if you only intend to use the interface methods outside of this package

discovery/api/v1/client/http.go Outdated Show resolved Hide resolved
discovery/api/v1/client/interface.go Show resolved Hide resolved
@reinkrul reinkrul merged commit 085c43d into master Jan 9, 2024
8 of 9 checks passed
@reinkrul reinkrul deleted the discovery/http-client branch January 9, 2024 09:27
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

Successfully merging this pull request may close these issues.

3 participants