mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-11-11 07:41:10 +00:00
starter
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1 @@
|
||||
package configs
|
||||
|
||||
const (
|
||||
DbConfig = ""
|
||||
)
|
||||
|
||||
17
pkg/utl/db/db.go
Normal file
17
pkg/utl/db/db.go
Normal 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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user