project structure

This commit is contained in:
Fran Jurmanović
2021-05-02 20:35:00 +02:00
parent 9a272d47c4
commit 3a5138eb83
10 changed files with 292 additions and 0 deletions

9
pkg/utl/common/common.go Normal file
View File

@@ -0,0 +1,9 @@
package common
import "log"
func CheckError(err error) {
if err != nil {
log.Fatalf("Unable to execute the query. %v", err)
}
}

View File

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

20
pkg/utl/pg/pg.go Normal file
View File

@@ -0,0 +1,20 @@
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
}
}

22
pkg/utl/server/server.go Normal file
View File

@@ -0,0 +1,22 @@
package server
import (
"os"
"github.com/gin-gonic/gin"
)
func Start() *gin.Engine {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
port := os.Getenv("PORT")
if port == "" {
port = "4000"
}
r.Run(":" + port)
return r
}