-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (44 loc) · 1.35 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 (
"log"
"net/http"
"github.com/chibuikeIg/Rss_blog/config"
"github.com/chibuikeIg/Rss_blog/controllers"
"github.com/julienschmidt/httprouter"
)
func init() {
quit := make(chan struct{})
go controllers.FetchFeed(quit)
}
func main() {
// DB config
DB, cxtCancel := config.NewDatabase(1000)
defer cxtCancel()
defer func() {
if err := DB.Client().Disconnect(DB.Ctx); err != nil {
config.Log(err.Error())
}
}()
// routes
router := httprouter.New()
router.ServeFiles("/assets/*filepath", http.Dir("./public/assets"))
fc := controllers.NewFollowingController(DB)
lc := controllers.NewLoginController(DB)
hc := controllers.NewHomeController(DB)
ffc := controllers.NewFeedController(DB)
fsc := controllers.NewFeedSettingController(DB)
router.GET("/", hc.Index)
router.GET("/following", fc.Index)
router.GET("/following/latest-posts", fc.LatestPosts)
router.PUT("/following/:id/update", fc.Update)
router.DELETE("/following/:id/delete", fc.Delete)
router.GET("/following/feeds", ffc.Create)
router.POST("/following/feeds", ffc.Store)
router.DELETE("/feeds/:feed_id/delete", ffc.Delete)
router.GET("/feed/settings", fsc.Create)
router.POST("/feed/settings", fsc.Store)
router.GET("/login", lc.Create)
router.POST("/login", lc.Store)
router.GET("/logout", lc.Logout)
log.Fatal(http.ListenAndServe(":80", router))
}