-
Notifications
You must be signed in to change notification settings - Fork 607
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
Extract helper for connecting to Unix sockets #2922
base: master
Are you sure you want to change the base?
Conversation
r? @nirs |
c1c8174
to
4bea537
Compare
@@ -27,7 +28,7 @@ func PassFDToUnix(unixSock string) (*os.File, error) { | |||
if err != nil { | |||
return nil, err | |||
} | |||
err = fd.Put(unixConn.(*net.UnixConn), server) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have to introduce a new netutil
package just for avoiding this single type assertion.
If you want to avoid a potential panic, you can just check conn, ok := unixConn.(*net.UnixConn); if !ok { return errors.New(...)}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have to introduce a new netutil
package just for avoiding this single type assertion.
If you want to avoid a potential panic, you can just check conn, ok := unixConn.(*net.UnixConn); if !ok { return errors.New(...)}
Because this pattern occurs in a number of places (connecting to a UNIX socket, not the type assertion), this is reducing all that duplication.
I don't think a panic is a real concern. This is just cleanup. |
4bea537
to
5c4985e
Compare
@nirs this is what you wanted, no? |
I suggested to add a helper which would solve the issue for the vz package. The current change is little bit bigger and handle all unix sockets in lima (good), but it is hard to sell it as a way to avoid type assertions since we have only one. I did have time to review all the changes, but I think this will be easier to swallow if we change the commit/pr title/message to describe why creating unix socket in this way is better. |
net.UnixConn
type assertionsExtract netutil to house a new `DialUnix` that hides the messier interface presented by the standard library. Use this new helper to avoid a type assertion. Signed-off-by: Tamir Duberstein <tamird@gmail.com>
5c4985e
to
b112727
Compare
Updated both the PR title and the commit message. |
See commit message.