Library for manage postgresql config and connection.
Library contains:
- common postgresql config struct
- connection manager
- small function-helpers for work with transaction statement
Examples of create connection and write database communication code
package main
import (
commonEnvConfig "github.com/crypto-bundle/bc-wallet-common-lib-configs/pkg/envconfig"
commonPostgres "github.com/crypto-bundle/bc-wallet-common-lib-postgres/pkg/postgres"
commonVault "github.com/crypto-bundle/bc-wallet-common-lib-vault/pkg/vault"
commonVaultTokenClient "github.com/crypto-bundle/bc-wallet-common-lib-vault/pkg/vault/client/token"
)
type VaultWrappedConfig struct {
*commonVault.BaseConfig
*commonVaultTokenClient.AuthConfig
}
func main() {
// vault prepare
vaultSrv, err := commonVault.NewService(ctx, vaultCfg, vaultClientSrv)
if err != nil {
panic(err)
}
_, err = vaultSrv.Login(ctx)
if err != nil {
panic(err)
}
pgConfig := commonPostgres.PostgresConfig{}
pgCfgPreparerSrv := commonEnvConfig.NewConfigManager()
err = pgCfgPreparerSrv.PrepareTo(pgConfig).With(vaultSrv).Do(ctx)
if err != nil {
panic(err)
}
pgConn := commonPostgres.NewConnection(context.Background(), pgConfig, loggerSvc)
_, err = pgConn.Connect()
if err != nil {
panic(err)
}
}
- Author and maintainer - @gudron (Alex V Kotelnikov)
bc-wallet-common-lib-postgres is licensed under the MIT License.