Skip to content

Sets Postgres environment variables to a config type

License

Notifications You must be signed in to change notification settings

joegasewicz/pg-conf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PG Conf

Sets Postgres environment variables to a config type

Environment variables will override defaults set on PostgresConfig, making it simple for creating a local default config.

Example

os.Setenv("PGHOST", "www.google.com")
os.Setenv("PGUSER", "John")
os.Setenv("PGPASSWORD", "wizard")
os.Setenv("PGDATABASE", "happy_db")
os.Setenv("PGPORT", "1234")
os.Setenv("PGSSLMODE", "verify-ca")

type Config struct {
    *pg_conf.PostgresConfig
}

cfg := Config{
    PostgresConfig: &PostgresConfig{
      // Add defaults here if requires... (env vars will override defaults)
    },
}

pg_conf.Update(cfg.PostgresConfig)

connStr := cfg.PostgresConfig.GetPostgresConnStr()
// result - "host=www.google.com user=John dbname=happy_db password=wizard port=1234 sslmode=verify-ca"

About

Sets Postgres environment variables to a config type

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages