Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WaitForConnect ¶
WaitForConnect on a port progressively backing off returns false if we couldn't establish a connection uses default timeout of 5 seconds
Example ¶
WaitForConnect will attempt to connect and timeout after 10 retries of up to 5 seconds
package main import ( "fmt" "github.com/xplorfin/netutils" ) func main() { // will attempt to connect and not timeout since url is valid successful := netutils.WaitForConnect("https://entropy.rocks") if successful { fmt.Println("connected to entropy!") } }
func WaitForConnectTimeout ¶
WaitForConnectTimeout will wait for a connection on a port progressively backing off returns false if we couldn't establish a connection by timeout after 10 timeouts
Example ¶
WaitForConnectTimeout will attempt to connect and timeout after 5 seconds
package main import ( "fmt" "time" "github.com/xplorfin/netutils" ) func main() { // will attempt to connect and not timeout since url is valid successful := netutils.WaitForConnectTimeout("https://entropy.rocks", 5*time.Second) if successful { fmt.Println("connected to entropy!") } successful = netutils.WaitForConnectTimeout("https://entropy.rockssocks", time.Millisecond) if !successful { fmt.Println("could not connect to non-existent domain") } }
Types ¶
type FreePortStack ¶
type FreePortStack struct {
// contains filtered or unexported fields
}
FreePortStack stack allows you to locally store a list of autogenerated ports it is stateful to make sure ports aren't reused
func NewFreeportStack ¶
func NewFreeportStack() FreePortStack
NewFreeportStack is a helper method to initialize a freeport stack
func (*FreePortStack) GetFreePort ¶
func (s *FreePortStack) GetFreePort() (port int, err error)
GetFreePort gets a free port that has not already been used in the stack returns errors if they exist
Example ¶
Freeport stack gets multiple freeports that are non overlapping
package main import ( "github.com/xplorfin/netutils" "github.com/xplorfin/netutils/testutils" ) func main() { // create a port stack stack := netutils.NewFreeportStack() // stack.GetPort will guarantee the ports have not been used before in the stack for _, port := range []int{stack.GetPort(), stack.GetPort()} { port := port go func() { err := testutils.MockHTTPServer(port) if err != nil { panic(err) } }() } }
func (*FreePortStack) GetPort ¶
func (s *FreePortStack) GetPort() (port int)
GetPort gets a free port that has not already been used in the stack panics on error
Directories
¶
Path | Synopsis |
---|---|
Package fasthttp contains fasthttp specific utilities for handling compression, authorization, and more
|
Package fasthttp contains fasthttp specific utilities for handling compression, authorization, and more |
Package testutils contains utilties for mocking various kinds of network interfaces and asserting networked events did or did not happen
|
Package testutils contains utilties for mocking various kinds of network interfaces and asserting networked events did or did not happen |