An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# gopool
[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/github.com/damoye/gopool)
[![Build Status](https://travis-ci.org/damoye/gopool.svg?branch=master)](https://travis-ci.org/damoye/gopool)
[![Coverage Status](https://coveralls.io/repos/github/damoye/gopool/badge.svg?branch=master)](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