Skip to content

Commit

Permalink
fix: added ability to encrypt db connection
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-cardenas-coding committed Jan 6, 2023
1 parent 8981df5 commit 025c6cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The API server accepts the following environment variables.
| `DB_USER` | The database user name to use for queries. | `postgres` |
| `DB_HOST` | The hostname or url to the database. | `localhost` |
| `DB_PASSWORD` | The database password. | `password` |
| `DB_ENCRYPTION`| The Postgres [ssl mode](https://www.postgresql.org/docs/current/libpq-ssl.html) behavior to enable. Allowed values are: `require`, `verify-full`, `verify-ca`, or `disable` |`require`|
| `DB_INIT` | Set to `true` if you want the API server to create the required database schema and tables in the target database.| `false` |


4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ func init() {
dbName = internal.Getenv("DB_NAME", "counter")
dbUser = internal.Getenv("DB_USER", "postgres")
dbHost = internal.Getenv("DB_HOST", "localhost")
dbEncryption := internal.Getenv("DB_ENCRYPTION", "disable")
dbPassword = internal.Getenv("DB_PASSWORD", "password")
dbPort = internal.StringToInt64(internal.Getenv("DB_PORT", "5432"))
db, err := sqlx.Open(db_driver, fmt.Sprintf(
"host=%s port=%d dbname=%s user=%s password=%s connect_timeout=5 sslmode=disable",
"host=%s port=%d dbname=%s user=%s password=%s connect_timeout=5 sslmode=%s",
dbHost,
dbPort,
dbName,
dbUser,
dbPassword,
dbEncryption,
))
if err != nil {
log.Fatal().Err(err).Msg("Error connecting to database")
Expand Down

0 comments on commit 025c6cc

Please sign in to comment.