Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sokil/go-connection-pool
Connection pool is a thread safe list of net.Conn
https://github.com/sokil/go-connection-pool
connection-pool go golang
Last synced: 23 days ago
JSON representation
Connection pool is a thread safe list of net.Conn
- Host: GitHub
- URL: https://github.com/sokil/go-connection-pool
- Owner: sokil
- License: mit
- Created: 2017-09-28T02:52:12.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-23T07:17:46.000Z (over 6 years ago)
- Last Synced: 2024-10-09T20:59:47.953Z (about 1 month ago)
- Topics: connection-pool, go, golang
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-connection-pool
Connection pool is a thread safe list of net.Conn
[![Go Report Card](https://goreportcard.com/badge/github.com/sokil/go-connection-pool)](https://goreportcard.com/report/github.com/sokil/go-connection-pool)
[![GoDoc](https://godoc.org/github.com/sokil/go-connection-pool?status.svg)](https://godoc.org/github.com/sokil/go-connection-pool)
[![Code Climate](https://codeclimate.com/github/sokil/go-connection-pool/badges/gpa.svg)](https://codeclimate.com/github/sokil/go-connection-pool)
## Basic usage```go
socket, err := net.Listen("tcp", "127.0.0.1:8080")
// prepare connection pool
connectionPool := connectionPool.NewConnectionPool()
// accept connection
connection, err := socket.Accept()
// add connection to pool
connectionId := connectionPool.Add(connection)// get connection and read
reader := bufio.NewReader(connectionPool.Get(connectionId))// count of connections in pool
size := connectionPool.Size()// send message to all connections in pool
connectionPool.Range(func(targetConnection net.Conn, targetConnectionId int) {
writer := bufio.NewWriter(targetConnection)
writer.WriteString("Some message\n")
writer.Flush()
})// remove connection from bool
connectionPool.Remove(connectionId)
```