-
Notifications
You must be signed in to change notification settings - Fork 9
Support connection over Unix socket #18
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
base: master
Are you sure you want to change the base?
Conversation
e605e00
to
bfeaa53
Compare
I've updated the PR to preserve retro-compatibility. |
I was thinking that maybe it's better to change the type Dialer func(context.Context) (net.Conn, error)
func new (Dialer d) {
return &Client{dialer: d}
} And then it can be used with both TCP and Unix connections: dialer := net.Dialer{Timeout: 20 * time.Second}.
New(func(ctx context.Context) (net.Conn, error) {
conn := dialer.DialContext(ctx, "tcp", "17.0.0.1")
conn.SetDeadline(time.Now().Add(dialer.Timeout))
return conn, nil
}) The func TCPDialer(addr string) Dialer {
return func(ctx context.Context) (net.Conn, error) {
// ...
}
} So you can connect with:
What do you think? |
btw another common use case that should work without a lot of effort is connecting over TLS/SSL. |
It would look way better but it will break retro-compatibility. If that's not an issue then let's go for it ! |
Compatibility isn't an issue as far as I'm concerned. I don't think there are a lot of people using it, and there is no "1.0" (exactly so that I could change the connection logic). |
Okay perfect, then I'll try to update the PR! :) |
bfeaa53
to
5ec6dd6
Compare
Is it close that what you had in mind? |
5ec6dd6
to
5c48b44
Compare
Codecov Report
@@ Coverage Diff @@
## master #18 +/- ##
==========================================
- Coverage 75.66% 75.19% -0.48%
==========================================
Files 2 2
Lines 374 379 +5
==========================================
+ Hits 283 285 +2
- Misses 53 55 +2
- Partials 38 39 +1
Continue to review full report at Codecov.
|
Do you need the coverage check to pass? |
FYI I've tested it on a personal project and it works 🎉 |
Thanks! Look good at a glance; I'll test and go over it later. |
- Some small documentation fixes. - Unexport the BuildGenericDialer() function for now. I'm not sure how useful it is to have this exported. - The Client.dial() function is rather redundant now, so remove that.
Hm, need to think about the API for a bit here. Can't say I particularly like this.
api.go
Outdated
func New(d Dialer) *Client { | ||
return &Client{dialer: d} | ||
} | ||
|
||
// BuildGenericDialer is a generic method to build a Dialer (cf `New` method) | ||
func BuildGenericDialer(addr string, proto string, timeout time.Duration) Dialer { |
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.
@Carpetsmoker This was useful because it provided a way to specify the timeout. Without it the 20sec timeout is imposed.
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.
@Carpetsmoker any update on this PR? :)
Fix #16