https://github.com/mushroomsir/socket
https://github.com/mushroomsir/socket
simple-api
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/mushroomsir/socket
- Owner: mushroomsir
- License: mit
- Created: 2017-02-28T09:44:55.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-03T02:06:31.000Z (almost 9 years ago)
- Last Synced: 2024-06-20T03:46:16.709Z (over 1 year ago)
- Topics: simple-api
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# socket
[](https://travis-ci.org/mushroomsir/socket)
[](https://coveralls.io/r/mushroomsir/socket)
[](https://raw.githubusercontent.com/mushroomsir/socket/master/LICENSE)
[](http://godoc.org/github.com/mushroomsir/socket)
## Installation and Usage
Install the package with:
```go
go get github.com/mushroomsir/socket
```
Import it with:
```go
import "github.com/mushroomsir/socket"
```
and use `socket` as the package name inside the code.
## Features
* Simple API: use it as an easy way to reuse socket(net.conn)
* Socket support Ping() func
## Example
```go
// create a new socket pool with an initial capacity of 5 and maximum
// capacity of 30. The factory will create 5 initial connections and put it
// into the pool.
pool, err := socket.NewPool(1, 20, socket.NewFactory(address))
// now you can get a connection from the pool, if there is no connection
// available it will create a new one via the factory function.
socket, err := pool.Get()
// Ping to detect whether the socket is closed.
b, err := socket.Ping()
// close pool any time you want
pool.Close()
```