-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
41 lines (35 loc) · 1.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"log"
"survivorcoders.com/reminders/controller"
"survivorcoders.com/reminders/repository"
)
func main() {
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Connect to the "bank" database
dbConnection, err := gorm.Open(postgres.Open("postgres://localhost:5432/reminders"), &gorm.Config{})
if err != nil {
log.Fatal("error configuring the database: ", err)
}
log.Println("Hey! You successfully connected to your CockroachDB cluster.")
// Routes
reminderController := controller.ReminderController{
ReminderRepository: repository.ReminderRepository{
DB: dbConnection,
},
}
e.GET("/reminders", reminderController.GetAll)
e.POST("/reminders", reminderController.Create)
e.GET("/reminders/:id", reminderController.Get)
e.PUT("/reminders/:id", reminderController.PUT)
e.DELETE("/reminders/:id", reminderController.Delete)
// Start server
e.Logger.Fatal(e.Start(":8080"))
}