This commit is contained in:
Fran Jurmanović
2021-05-06 20:09:29 +02:00
parent 3a5138eb83
commit 20894ee42e
18 changed files with 197 additions and 28 deletions

View File

@@ -4,6 +4,6 @@ import "log"
func CheckError(err error) {
if err != nil {
log.Fatalf("Unable to execute the query. %v", err)
log.Fatalf("Error occured. %v", err)
}
}

View File

@@ -1,5 +1 @@
package configs
const (
DbConfig = ""
)

17
pkg/utl/db/db.go Normal file
View File

@@ -0,0 +1,17 @@
package db
import (
"fmt"
"wallet-api/pkg/utl/common"
"github.com/go-pg/pg/v10"
)
func CreateConnection(dbUrl string) *pg.DB {
opt, err := pg.ParseURL(dbUrl)
common.CheckError(err)
conn := pg.Connect(opt)
fmt.Println("Successfully connected!")
return conn
}

View File

@@ -1,20 +0,0 @@
package pg
import (
"fmt"
"os"
"wallet-api/pkg/utl/common"
"github.com/go-pg/pg/v10"
)
func CreateConnection() func() *pg.DB {
opt, err := pg.ParseURL(os.Getenv("DATABASE_URL"))
common.CheckError(err)
db := pg.Connect(opt)
fmt.Println("Successfully connected!")
return func() *pg.DB {
return db
}
}

View File

@@ -6,8 +6,7 @@ import (
"github.com/gin-gonic/gin"
)
func Start() *gin.Engine {
r := gin.Default()
func Start(r *gin.Engine) *gin.Engine {
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",