-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
41 lines (30 loc) · 832 Bytes
/
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 (
"flag"
"log"
"points/db"
"points/handlers"
"points/models"
"github.com/gin-gonic/gin"
)
func main() {
migration := flag.Bool("migrations", false, "Realizar migrations do banco de dados")
flag.Parse()
db, err := db.OpenDBConnection()
if err != nil {
log.Fatal("failed to connect database")
}
if *migration {
log.Println("Executando migrations...")
db.AutoMigrate(&models.Customer{}, &models.Transaction{}, &models.TransactionProduct{}, &models.Product{})
log.Println("ok")
}
r := gin.Default()
r.Use(gin.Recovery())
r.GET("customers/:id", handlers.GetCustomerByID)
r.GET("customers/", handlers.GetCustomers)
r.POST("customers/", handlers.PostCustomer)
r.PUT("customers/:id", handlers.PutCustomer)
r.POST("/transactions", handlers.PostTransaction)
r.Run("0.0.0.0:8081")
}