Skip to content

Commit

Permalink
fixed env load for db creds in api backend
Browse files Browse the repository at this point in the history
  • Loading branch information
anistark committed Oct 2, 2024
1 parent 5f4656d commit 6d40789
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ require (
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
github.com/jjti/go-spancheck v0.6.2 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/julz/importas v0.1.0 // indirect
github.com/karamaru-alpha/copyloopvar v1.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
Expand Down
8 changes: 8 additions & 0 deletions backend/pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"database/sql"
"errors"
"fmt"
"log"
"os"
"strconv"

//register "pgx" sql driver
"github.com/doug-martin/goqu/v9"
"github.com/jmoiron/sqlx"
"github.com/joho/godotenv"
migrate "github.com/rubenv/sql-migrate"

"github.com/kinvolk/nebraska/backend/pkg/util"
Expand Down Expand Up @@ -75,6 +77,12 @@ type API struct {

// New creates a new API instance, creates the underlying db connection.
func New(options ...func(*API) error) (*API, error) {
// Load .env
envErr := godotenv.Load()
if envErr != nil {
log.Fatal("Error loading .env file")
}

api := &API{
dbDriver: "pgx",
dbURL: os.Getenv("NEBRASKA_DB_URL"),
Expand Down

0 comments on commit 6d40789

Please sign in to comment.