https://github.com/damoye/gopool
net.Conn pool for Go
https://github.com/damoye/gopool
go network
Last synced: 12 months ago
JSON representation
net.Conn pool for Go
- Host: GitHub
- URL: https://github.com/damoye/gopool
- Owner: damoye
- License: mit
- Created: 2017-03-19T04:11:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-19T12:48:41.000Z (over 9 years ago)
- Last Synced: 2024-06-20T14:17:48.529Z (about 2 years ago)
- Topics: go, network
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gopool
[](https://godoc.org/github.com/damoye/gopool)
[](https://travis-ci.org/damoye/gopool)
[](https://coveralls.io/github/damoye/gopool?branch=master)
Pool is a thread safe pool for net.Conn. It can be used to manage and reuse connections.
## Install and Usage
Install the package with:
```bash
go get github.com/damoye/gopool
```
Import it with:
```go
import "github.com/damoye/gopool"
```
and use `pool` as the package name inside the code.
## Example
```go
dialer := func() (net.Conn, error) { return net.Dial("tcp", "127.0.0.1:4000") }
p, err := pool.New(30, dialer)
if err != nil {
log.Fatal(err)
}
conn, err := p.Get()
if err != nil {
log.Fatal(err)
}
// Do something with conn
_, err = conn.Write("hello world")
if err != nil {
conn.Close()
} else {
p.Put(conn)
}
```
## License
The MIT License (MIT) - see LICENSE for more details