feat: group routes
This commit is contained in:
parent
4868e4d7cf
commit
a376800eeb
7
main.go
7
main.go
|
@ -97,8 +97,10 @@ func main() {
|
|||
corsConfig.AllowHeaders = []string{"hx-current-url", "hx-request"}
|
||||
r.Use(cors.New(corsConfig))
|
||||
|
||||
blogForm := r.Group("/blog/api/")
|
||||
{
|
||||
// Get the emoji form, you must provide postId query parameter
|
||||
r.GET("/forms/emoji", func(c *gin.Context) {
|
||||
blogForm.GET("/forms/emoji", func(c *gin.Context) {
|
||||
postId := c.Query("postId")
|
||||
|
||||
// get emoji counts for each emoji
|
||||
|
@ -118,7 +120,7 @@ func main() {
|
|||
// Update the emoji counter, this handler will
|
||||
// add a new entry to the database with anonymized ip
|
||||
// then sums the results to get the emoji counter
|
||||
r.POST("/forms/emoji/post", func(c *gin.Context) {
|
||||
blogForm.POST("/forms/emoji/post", func(c *gin.Context) {
|
||||
postId := c.PostForm("postId")
|
||||
emoji := c.PostForm("emojiInput")
|
||||
|
||||
|
@ -145,6 +147,7 @@ func main() {
|
|||
// Return the html with the updated emoji counter
|
||||
c.HTML(http.StatusOK, "emoji_form.tmpl", gin.H{"postId": postId, "results": emojiCounter})
|
||||
})
|
||||
}
|
||||
|
||||
r.Run(":8000")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user