Skip to content

Commit

Permalink
Created a migrations file and a database connection
Browse files Browse the repository at this point in the history
  • Loading branch information
CrustyDev committed Oct 4, 2023
1 parent 10f06a7 commit 09acea3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
npm-debug.log
postgres_data
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ make up # Start Docker containers in the background
````

***
Your API will be running on http://localhost:80
Your API will be running on http://localhost/api/

Test whether API is up at http://localhost/api/v1/healthcheck
Test whether API is up at http://localhost/api/ping
***
14 changes: 6 additions & 8 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gofiber/fiber/v2/middleware/logger"

config "github.com/CodeChefVIT/cookoff-backend/config"
"github.com/CodeChefVIT/cookoff-backend/internal/database"
)

func main() {
Expand All @@ -18,8 +19,8 @@ func main() {
log.Fatalln("Failed to load environment variables! \n", err.Error())
}

// database.ConnectDB(&config)
//database.RunMigrations(database.DB)
database.ConnectDB(&config)
database.RunMigrations(database.DB)

app.Use(logger.New())

Expand All @@ -29,15 +30,12 @@ func main() {
AllowMethods: "GET, POST, PATCH, DELETE",
AllowCredentials: true,
}))

apiGroup := app.Group("/v1")

// routes.AuthRoutes(apiGroup)

apiGroup.Get("/healthcheck", func(c *fiber.Ctx) error {
app.Get("/ping", func(c *fiber.Ctx) error {
return c.Status(200).JSON(fiber.Map{
"status": "success",
"message": "icETITE-24 Backend API is up and running.",
"message": "pong",
"status": "Backend up and running",
})
})

Expand Down
41 changes: 41 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
module github.com/CodeChefVIT/cookoff-backend

go 1.21.1

require (
github.com/gofiber/fiber/v2 v2.49.2
github.com/spf13/viper v1.16.0
github.com/uptrace/bun v1.1.16
github.com/uptrace/bun/dialect/pgdialect v1.1.16
github.com/uptrace/bun/driver/pgdriver v1.1.16
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.49.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
mellium.im/sasl v0.3.1 // indirect
)
2 changes: 2 additions & 0 deletions internal/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ func ConnectDB(config *config.Config) {
log.Fatal("Could not connect to databse")
log.Printf("DSN = %s", dsn)
}

log.Println("Connection to database successful")
}

0 comments on commit 09acea3

Please sign in to comment.