-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (39 loc) · 1.21 KB
/
Copy pathmain.go
File metadata and controls
46 lines (39 loc) · 1.21 KB
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
package main
import (
"BackendAndroid/database"
"BackendAndroid/handlers"
"BackendAndroid/middleware"
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
// Initialize the database
database.InitDB()
// Create a Gin router
router := gin.Default()
// Public routes
router.POST("/register", handlers.Register)
router.POST("/login", handlers.Login)
router.GET("/poetry", handlers.GetPoetry)
router.GET("/poetryList/:n", handlers.GetPoetryList)
router.POST("/addFavorites", handlers.AddFavorite)
router.POST("/removeFavorites", handlers.RemoveFavorites)
router.GET("/getFavorites/:username", handlers.GetFavorites)
router.GET("/getFavoritesList/:username", handlers.GetFavoritesList)
router.POST("/saveNote", handlers.SaveNote)
router.GET("/delNote/:id", handlers.DelNote)
router.GET("/notes", handlers.GetNotes)
router.GET("/getUserNotes/:username", handlers.GetNoteByUsername)
// Protected routes
authGroup := router.Group("/api")
authGroup.Use(middleware.AuthMiddleware())
{
authGroup.GET("/profile", func(c *gin.Context) {
username := c.MustGet("username").(string)
c.JSON(http.StatusOK, gin.H{"message": "Welcome, " + username})
})
}
if err := router.Run(":8080"); err != nil {
panic(err)
}
}