Skip to content

Latest commit

 

History

History
97 lines (67 loc) · 2.71 KB

README.md

File metadata and controls

97 lines (67 loc) · 2.71 KB

TCP pooling

tag Go Version GoDoc Build Status Go report Coverage Contributors License

✨ Drop-in replacement to net.Conn with pooling and auto-reconnect.

🚀 Install

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.

💡 Usage

GoDoc: https://pkg.go.dev/github.com/samber/go-tcp-pool

Create a TCP connection 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(...)

🚀 @TODO

  • Implement round-robin connection pool
  • Implement auto-reconnect
  • Implement Read()
  • Implement other load-balancing strategies
    • Max idle time
    • MinConn + MaxConn

🤝 Contributing

Don't hesitate ;)

# Install some dev dependencies
make tools

# Run tests
make test
# or
make watch-test

👤 Contributors

Contributors

💫 Show your support

Give a ⭐️ if this project helped you!

GitHub Sponsors

📝 License

Copyright © 2023 Samuel Berthe.

This project is MIT licensed.