Skip to content

Commit

Permalink
added viper to get app configurations from .env
Browse files Browse the repository at this point in the history
  • Loading branch information
imrishuroy committed Nov 14, 2023
1 parent 449b592 commit ea65ec5
Show file tree
Hide file tree
Showing 6 changed files with 551 additions and 20 deletions.
3 changes: 3 additions & 0 deletions app.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DB_DRIVER=postgres
DB_SOURCE=postgresql://root:Prince2024@localhost:5432/simple_bank?sslmode=disable
SERVER_ADDRESS=localhost:8080
18 changes: 12 additions & 6 deletions db/sqlc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ import (
"os"
"testing"

"github.com/imrishuroy/simplebank/util"
_ "github.com/lib/pq"
)

const (
dbDriver = "postgres"
dbSource = "postgresql://root:Prince2024@localhost:5432/simple_bank?sslmode=disable"
)
// const (
// dbDriver = "postgres"
// dbSource = "postgresql://root:Prince2024@localhost:5432/simple_bank?sslmode=disable"
// )

var testQueries *Queries
var testDB *sql.DB

func TestMain(m *testing.M) {
var err error
testDB, err = sql.Open(dbDriver, dbSource)
config, err := util.LoadConfig("../..")
if err != nil {
log.Fatal("cannot load config:", err)

}

testDB, err = sql.Open(config.DBDriver, config.DBSource)
if err != nil {
log.Fatal("cannot connect to db:", err)
}
Expand Down
20 changes: 18 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,51 @@ go 1.21.1
require (
github.com/gin-gonic/gin v1.9.1
github.com/lib/pq v1.10.9
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
)

require (
github.com/bytedance/sonic v1.10.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.16.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.6.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit ea65ec5

Please # to comment.