-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
55 lines (45 loc) · 1.42 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
package main
import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"bareksa-news/modules/news/api"
TagsAPI "bareksa-news/modules/tags/api"
)
func main() {
r := gin.Default()
NewsController := api.NewsController{}
TagsController := TagsAPI.TagsController{}
//Setup CORS
corsConfig := cors.DefaultConfig()
corsConfig.AllowOrigins = []string{"*"}
r.Use(cors.New(corsConfig))
r.StaticFile("app.log", "./tmp/app.log")
r.NoRoute(func(c *gin.Context) {
c.JSON(404, gin.H{"message": "Page not found"})
})
newsRoute := r.Group("/news")
tagsRoute := r.Group("/tags")
//News
r.GET("/", responseToUser)
newsRoute.GET("/list", NewsController.List)
newsRoute.GET("/detail/:id", NewsController.Detail)
newsRoute.POST("/update/:id", NewsController.Update)
newsRoute.GET("/status/:status", NewsController.Status)
newsRoute.GET("/topic/:topic", NewsController.Topic)
newsRoute.POST("/add", NewsController.Add)
newsRoute.POST("/tag/add", NewsController.NewsTag)
newsRoute.DELETE("/delete/:id", NewsController.Delete)
//Tags
tagsRoute.GET("/", TagsController.List)
tagsRoute.POST("/add", TagsController.Add)
tagsRoute.GET("/detail/:id", TagsController.Detail)
tagsRoute.POST("/update", TagsController.Update)
tagsRoute.DELETE("/delete/:id", TagsController.Delete)
r.Run()
}
//ensure server is working properly, test with JSON response
func responseToUser(c *gin.Context) {
c.JSON(200, gin.H{
"Status" : "OK",
})
}