/
main.go
48 lines (40 loc) · 1.25 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
package main
import (
"fmt"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/rogierlommers/poddy/internal/common"
"github.com/rogierlommers/poddy/internal/poddy"
log "gopkg.in/inconshreveable/log15.v2"
)
func main() {
// read environment vars
common.ReadEnvironment()
// initialise mux router
router := mux.NewRouter()
// setup statics
poddy.CreateStaticBox(router)
// setup watchdirectory
log.Info("Watchdirectory in config", "directory", common.Watch)
if common.Watch != "" {
check, err := os.Stat(common.Watch)
if err != nil || !check.IsDir() {
log.Error("error setting up watchdirectory (point to directory?)")
} else {
poddy.EnableWatchdirectory(common.Watch)
}
}
// http handles
router.HandleFunc("/", poddy.IndexPage)
router.HandleFunc("/add-podcast", poddy.AddPodcast)
router.HandleFunc("/feed", poddy.Feed)
router.PathPrefix("/download").Handler(http.StripPrefix("/download", http.FileServer(http.Dir("storage/"))))
// start server
log.Info("poddy is running/listening", "host", common.Host, "port", common.Port)
err := http.ListenAndServe(fmt.Sprintf("%s:%d", common.Host, common.Port), router)
if err != nil {
log.Crit("daemon could not bind on interface", "host", common.Host, "port", common.Port)
os.Exit(1)
}
}