2019-07-28 18:56:18 +01:00
|
|
|
// Package pool is a connection pool
|
|
|
|
package pool
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2020-07-27 13:22:00 +01:00
|
|
|
"github.com/micro/go-micro/v3/transport"
|
2019-07-28 18:56:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Pool is an interface for connection pooling
|
|
|
|
type Pool interface {
|
|
|
|
// Close the pool
|
|
|
|
Close() error
|
|
|
|
// Get a connection
|
|
|
|
Get(addr string, opts ...transport.DialOption) (Conn, error)
|
2020-07-16 23:33:11 +08:00
|
|
|
// Release the connection
|
2019-07-28 18:56:18 +01:00
|
|
|
Release(c Conn, status error) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Conn interface {
|
|
|
|
// unique id of connection
|
|
|
|
Id() string
|
|
|
|
// time it was created
|
|
|
|
Created() time.Time
|
|
|
|
// embedded connection
|
|
|
|
transport.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPool(opts ...Option) Pool {
|
|
|
|
var options Options
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return newPool(options)
|
|
|
|
}
|