mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
project structure
This commit is contained in:
9
pkg/utl/common/common.go
Normal file
9
pkg/utl/common/common.go
Normal 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)
|
||||
}
|
||||
}
|
||||
5
pkg/utl/configs/configs.go
Normal file
5
pkg/utl/configs/configs.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package configs
|
||||
|
||||
const (
|
||||
DbConfig = ""
|
||||
)
|
||||
20
pkg/utl/pg/pg.go
Normal file
20
pkg/utl/pg/pg.go
Normal 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
22
pkg/utl/server/server.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user