Documentation ¶
Index ¶
- Constants
- type PostgresConnection
- func (c *PostgresConnection) Close(ctx context.Context, correlationId string) error
- func (c *PostgresConnection) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *PostgresConnection) GetConnection() *pgxpool.Pool
- func (c *PostgresConnection) GetDatabaseName() string
- func (c *PostgresConnection) IsOpen() bool
- func (c *PostgresConnection) Open(ctx context.Context, correlationId string) error
- func (c *PostgresConnection) SetReferences(ctx context.Context, references cref.IReferences)
- type PostgresConnectionResolver
- func (c *PostgresConnectionResolver) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *PostgresConnectionResolver) Resolve(ctx context.Context, correlationId string) (uri string, err error)
- func (c *PostgresConnectionResolver) SetReferences(ctx context.Context, references crefer.IReferences)
Constants ¶
const ( DefaultConnectTimeout = 1000 DefaultIdleTimeout = 10000 DefaultMaxPoolSize = 3 DefaultRetriesCount = 3 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PostgresConnection ¶
type PostgresConnection struct { // The logger. Logger *clog.CompositeLogger // The connection resolver. ConnectionResolver *PostgresConnectionResolver // The configuration options. Options *cconf.ConfigParams // The PostgreSQL connection pool object. Connection *pgxpool.Pool // The PostgreSQL database name. DatabaseName string // contains filtered or unexported fields }
PostgresConnection is a PostgreSQL connection using plain driver.
By defining a connection and sharing it through multiple persistence components you can reduce number of used database connections.
Configuration parameters - connection(s): - discovery_key: (optional) a key to retrieve the connection from IDiscovery - host: host name or IP address - port: port number (default: 27017) - uri: resource URI or connection string with all parameters in it - credential(s): - store_key: (optional) a key to retrieve the credentials from ICredentialStore - username: user name - password: user password - options: - connect_timeout: (optional) number of milliseconds to wait before timing out when connecting a new client (default: 0) - idle_timeout: (optional) number of milliseconds a client must sit idle in the pool and not be checked out (default: 10000) - max_pool_size: (optional) maximum number of clients the pool should contain (default: 10) References - *:logger:*:*:1.0 (optional) ILogger components to pass log messages - *:discovery:*:*:1.0 (optional) IDiscovery services - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
func NewPostgresConnection ¶
func NewPostgresConnection() *PostgresConnection
NewPostgresConnection creates a new instance of the connection component.
func (*PostgresConnection) Close ¶
func (c *PostgresConnection) Close(ctx context.Context, correlationId string) error
Close component and frees used resources.
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. Returns: error or nil no errors occurred
func (*PostgresConnection) Configure ¶
func (c *PostgresConnection) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure component by passing configuration parameters.
Parameters: - ctx context.Context - config configuration parameters to be set.
func (*PostgresConnection) GetConnection ¶
func (c *PostgresConnection) GetConnection() *pgxpool.Pool
func (*PostgresConnection) GetDatabaseName ¶
func (c *PostgresConnection) GetDatabaseName() string
func (*PostgresConnection) IsOpen ¶
func (c *PostgresConnection) IsOpen() bool
IsOpen checks if the component is opened.
Returns true if the component has been opened and false otherwise.
func (*PostgresConnection) Open ¶
func (c *PostgresConnection) Open(ctx context.Context, correlationId string) error
Open the component. Parameters:
- ctx context.Context
- correlationId (optional) transaction id to trace execution through call chain.
- Return error or nil no errors occurred.
func (*PostgresConnection) SetReferences ¶
func (c *PostgresConnection) SetReferences(ctx context.Context, references cref.IReferences)
SetReferences references to dependent components.
Parameters: - ctx context.Context - references references to locate the component dependencies.
type PostgresConnectionResolver ¶
type PostgresConnectionResolver struct { // The connections' resolver. ConnectionResolver *cconn.ConnectionResolver // The credentials' resolver. CredentialResolver *cauth.CredentialResolver }
PostgresConnectionResolver a helper struct that resolves Postgres connection and credential parameters, validates them and generates a connection URI. It is able to process multiple connections to Postgres cluster nodes.
Configuration parameters: - connection(s): - discovery_key: (optional) a key to retrieve the connection from IDiscovery - host: host name or IP address - port: port number (default: 27017) - database: database name - uri: resource URI or connection string with all parameters in it - credential(s): - store_key: (optional) a key to retrieve the credentials from ICredentialStore - username: user name - password: user password References: - *:discovery:*:*:1.0 (optional) IDiscovery services - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
func NewPostgresConnectionResolver ¶
func NewPostgresConnectionResolver() *PostgresConnectionResolver
NewPostgresConnectionResolver creates new connection resolver
Returns: *PostgresConnectionResolver
func (*PostgresConnectionResolver) Configure ¶
func (c *PostgresConnectionResolver) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure is configures component by passing configuration parameters.
Parameters: - ctx context.Context - config *cconf.ConfigParams configuration parameters to be set.
func (*PostgresConnectionResolver) Resolve ¶
func (c *PostgresConnectionResolver) Resolve(ctx context.Context, correlationId string) (uri string, err error)
Resolve method are resolves Postgres connection URI from connection and credential parameters.
Parameters: - ctx context.Context - correlationId string (optional) transaction id to trace execution through call chain. Returns: uri string, err error resolved URI and error, if this occured.
func (*PostgresConnectionResolver) SetReferences ¶
func (c *PostgresConnectionResolver) SetReferences(ctx context.Context, references crefer.IReferences)
SetReferences is sets references to dependent components. Parameters:
- ctx context.Context
- references crefer.IReferences references to locate the component dependencies.