go-micro.dev/v5@v5.12.0/util/pool/pool.go (about)

     1  // Package pool is a connection pool
     2  package pool
     3  
     4  import (
     5  	"time"
     6  
     7  	"go-micro.dev/v5/transport"
     8  )
     9  
    10  // Pool is an interface for connection pooling.
    11  type Pool interface {
    12  	// Close the pool
    13  	Close() error
    14  	// Get a connection
    15  	Get(addr string, opts ...transport.DialOption) (Conn, error)
    16  	// Release the connection
    17  	Release(c Conn, status error) error
    18  }
    19  
    20  // Conn interface represents a pool connection.
    21  type Conn interface {
    22  	// unique id of connection
    23  	Id() string
    24  	// time it was created
    25  	Created() time.Time
    26  	// embedded connection
    27  	transport.Client
    28  }
    29  
    30  // NewPool will return a new pool object.
    31  func NewPool(opts ...Option) Pool {
    32  	var options Options
    33  	for _, o := range opts {
    34  		o(&options)
    35  	}
    36  
    37  	return newPool(options)
    38  }