-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (42 loc) · 1.34 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
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/rogierlommers/greedy/internal/articles"
"github.com/rogierlommers/greedy/internal/common"
"github.com/rogierlommers/greedy/internal/reminders"
"github.com/rogierlommers/greedy/internal/render"
"github.com/sirupsen/logrus"
)
func main() {
// read environment vars and setup http client
common.ReadEnvironment()
articles.NewClient()
reminders.NewClient()
// initialize bolt storage
articles.Open()
defer articles.Close()
// initialize mux router
router := mux.NewRouter()
// selfdiagnose
common.SetupSelfdiagnose()
// setup statics
render.CreateStaticBox()
// http handles
router.HandleFunc("/", articles.IndexPage)
router.HandleFunc("/add", articles.AddArticle)
router.HandleFunc("/rss", articles.DisplayRSS)
router.HandleFunc("/export", articles.ExportCSV)
router.HandleFunc("/remind-url", reminders.AddReminderByURL)
router.HandleFunc("/remind-text", reminders.AddReminderByText)
// schedule cleanup routing
articles.ScheduleCleanup()
// start server
http.Handle("/", router)
logrus.Infof("deamon running on host %s and port %d", common.Host, common.Port)
err := http.ListenAndServe(fmt.Sprintf("%s:%d", common.Host, common.Port), nil)
if err != nil {
logrus.Panicf("daemon could not bind on interface: %s, port: %d", common.Host, common.Port)
}
}