Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 1.08 KB

README.md

File metadata and controls

40 lines (27 loc) · 1.08 KB

contextual

build status godoc

Supercharge Go Dialer with DialContext, providing support for context.Context in libraries with only Dial or DialTimeout methods. Extracted from and used in production at domainr.com.

Install

go get github.com/nbio/contextual

Usage

// Example context
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

// SSH into a proxy host
client, err := ssh.Dial("tcp", "yourserver.com:22", sshConfig)
if err != nil {
    return err
}

// Wrap the ssh.Client in contextual.Dialer to get DialContext
conn, err := contextual.Dialer{client}.DialContext(ctx, "tcp", "otherserver.com:12345")
if err != nil {
    return err // Could be context.DeadlineExceeded or context.Canceled
}

// Do stuff

Keywords

go, golang, context

Author

© 2017 nb.io, LLC