✨ Drop-in replacement to net.Conn
with pooling and auto-reconnect.
go get github.com/samber/go-tcp-pool
This library is v1 and follows SemVer strictly. No breaking changes will be made to exported APIs before v2.0.0.
GoDoc: https://pkg.go.dev/github.com/samber/go-tcp-pool
# Start a tcp server
ncat -l 9999 -k
import pool "github.com/samber/go-tcp-pool"
conn, err := pool.Dial("tcp", "localhost:9999")
if err != nil {
log.Fatal(err)
}
conn.SetPoolSize(10)
conn.SetMaxRetries(10)
conn.SetRetryInterval(10 * time.Millisecond)
// a tcp connection will be used in a round-robin manner
n, err := conn.Write([]byte("Hello, world!\n"))
if err != nil {
log.Fatal(err)
}
// will always return an error
conn.Read(...)
- Implement round-robin connection pool
- Implement auto-reconnect
- Implement Read()
- Implement other load-balancing strategies
- Max idle time
- MinConn + MaxConn
- Ping me on Twitter @samuelberthe (DMs, mentions, whatever :))
- Fork the project
- Fix open issues or request new features
Don't hesitate ;)
# Install some dev dependencies
make tools
# Run tests
make test
# or
make watch-test
Give a ⭐️ if this project helped you!
Copyright © 2023 Samuel Berthe.
This project is MIT licensed.