Skip to content

Add DialContext to Go structs, like magic!

License

Notifications You must be signed in to change notification settings

nbio/contextual

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages