Go connection pool managing reusable TCP connections with error handling and cleanup.
// Source: https://github.com/tarampampam/webhook-tester | License: MIT | Copyright Paramtamtam
// Provided via justclaw.it.com; keep this notice with the code.
package tunnel
import (
"context"
"net"
"sync"
)
type (
ConnectionsPool struct {
poolCh chan Connection // a channel to keep active connections
needNewCh chan struct{} // a channel with notifications about the need to create a new connection
stop chan struct{} // a channel to stop all goroutines
onError func(error) // may be nil or a function to call on error
dialer func(_ context.Context, network, address string) (net.Conn, error)
}
Connection struct {
Conn net.Conn
onRelease func() // a function to call when the connection is released
}
)
// Release closes the connection and noti
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key