This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (48 loc) · 1.49 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"flatman-api/controllers"
"flatman-api/middlewares"
"flatman-api/models"
"fmt"
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
)
func main() {
models.ConnectDataBase()
r := gin.Default()
r.Use(middlewares.CORSMiddleware())
public := r.Group("/api")
public.POST("/login", controllers.Login)
public.GET("/version", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"version": "1.0"})
})
private := r.Group("/api")
private.Use(middlewares.JwtAuthMiddleware())
{
// User Info
private.GET("/user", controllers.CurrentUser)
// Flat API
private.GET("/flat", controllers.GetFlats)
private.GET("/flat/:id", controllers.GetFlat)
private.POST("/flat", controllers.SaveFlat)
private.PUT("/flat/:id", controllers.UpdateFlat)
private.DELETE("/flat/:id", controllers.DeleteFlat)
// Lessee API
private.GET("/lessee", controllers.GetLessees)
private.GET("/lessee/:id", controllers.GetLessee)
private.POST("/lessee", controllers.SaveLessee)
private.PUT("/lessee/:id", controllers.UpdateLessee)
private.DELETE("/lessee/:id", controllers.DeleteLessee)
// Balance API
private.GET("/balance", controllers.GetBalances)
private.GET("/balance/:id", controllers.GetBalance)
private.POST("/balance", controllers.SaveBalance)
private.PUT("/balance/:id", controllers.UpdateBalance)
private.DELETE("/balance/:id", controllers.DeleteBalance)
}
if err := r.Run(fmt.Sprintf(":%s", os.Getenv("PORT"))); err != nil {
log.Fatalf("Error starting server")
}
}