Skip to content

Commit

Permalink
add environment variable file
Browse files Browse the repository at this point in the history
  • Loading branch information
moslehazizi committed Nov 25, 2023
1 parent 1a56e02 commit 874be52
Show file tree
Hide file tree
Showing 9 changed files with 803 additions and 34 deletions.
4 changes: 2 additions & 2 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

// Server serve HTTP requests for inventory_management services
type Server struct {
store *db.Store
store db.Store
router *gin.Engine
}

func NewServer(store *db.Store) *Server {
func NewServer(store db.Store) *Server {
server := &Server{store: store}
router := gin.Default()

Expand Down
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=postgres://mosleh:1234@localhost:5432/inventory_management?sslmode=disable
SERVER_ADDRESS=0.0.0.0:8080
243 changes: 243 additions & 0 deletions db/mock/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions db/sqlc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ package db

import (
"database/sql"
"inventory_management/util"
"log"
"os"
"testing"

_ "github.com/lib/pq"
)

const (
dbDriver = "postgres"
dbSource = "postgres://mosleh:1234@localhost:5432/inventory_management?sslmode=disable"
)

var testQueries *Queries

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

conn, err := sql.Open(config.DBDriver, config.DBSource)
if err != nil {
log.Fatal("Connot connect to the database:", err)
}
Expand Down
20 changes: 10 additions & 10 deletions db/sqlc/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import (
)

// Store provides all functions to execute do queries and transactions
type Store struct {
type Store interface {
Querier
}

// SQLStore provides all functions to execute SQL queries and transactions
type SQLStore struct {
*Queries
db *sql.DB
}

func NewStore(db *sql.DB) *Store {
return &Store{
func NewStore(db *sql.DB) Store {
return &SQLStore{
db: db,
Queries: New(db),
}
}


// Here is place for implement all transaction in future





// // execTx executes a function within a database transaction
// func (store *Store) execTx(c context.Context, fn func(*Queries) error) error {
// tx, err := store.db.BeginTx(c, nil)
Expand All @@ -34,9 +34,9 @@ func NewStore(db *sql.DB) *Store {
// err = fn(q)
// if err != nil{
// if rbErr := tx.Rollback(); rbErr != nil {
// return fmt.Errorf("tx err: %v, rb err: %v", err, rbErr)
// return fmt.Errorf("tx err: %v, rb err: %v", err, rbErr)
// }
// return err
// }
// return tx.Commit()
// }
// }
29 changes: 23 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,54 @@ module inventory_management

go 1.20

require github.com/lib/pq v1.10.9
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.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // 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/golang/mock v1.6.0 // 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/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // 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/multierr v1.11.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-20231110203233-9a3e6036ecaa // 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 874be52

Please sign in to comment.