-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (33 loc) · 1013 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
42
43
44
package main
import (
"github.com/gin-gonic/gin"
"github.com/towens182/budget/controller"
initializers "github.com/towens182/budget/initializers"
)
var (
transactionController controller.Controller = controller.NewTransactionController()
paymentController controller.Controller = controller.NewPaymentController()
)
func init() {
initializers.LoadEnvVaraiables()
}
func CORSMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Headers", "*")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(204)
return
}
c.Next()
}
}
func main() {
server := gin.Default()
server.Use(CORSMiddleware())
server.GET("/transactions", transactionController.GetAll)
server.POST("/transactions", transactionController.Add)
server.GET("/payments", paymentController.GetAll)
server.POST("/payments", paymentController.Add)
server.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}