-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchlist.go
98 lines (79 loc) · 2.92 KB
/
watchlist.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"log"
"net/http"
"time"
"github.com/Soesah/watchlist.lostmarbles.nl/server/config"
"github.com/Soesah/watchlist.lostmarbles.nl/server/handlers"
"github.com/Soesah/watchlist.lostmarbles.nl/server/middlewares"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
func main() {
config.Init()
conf := config.Get()
r := chi.NewRouter()
// middleware
r.Use(middleware.DefaultCompress)
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(middleware.Timeout(60 * time.Second))
r.Use(middleware.RedirectSlashes)
// home
r.Get("/", handlers.RootHandler)
r.Route("/api", func(r chi.Router) {
r.Get("/list", handlers.GetList)
r.Put("/series/{watched}/{imdbID}", handlers.ToggleSeriesWatched)
r.Put("/series/{watched}/{imdbID}/season/{seasonNr}", handlers.ToggleSeasonWatched)
r.Put("/series/{watched}/{imdbID}/season/{seasonNr}/episode/{episodeNr}", handlers.ToggleEpisodeWatched)
r.Put("/{type}/watched/{imdbID}", handlers.ToggleItemWatched)
r.Post("/movie", handlers.AddMovie)
r.Post("/series", handlers.AddSeries)
r.Post("/documentary", handlers.AddDocumentary)
r.Post("/game", handlers.AddGame)
r.Post("/franchise", handlers.AddFranchise)
r.Get("/movie/{imdbID}", handlers.GetMovie)
r.Get("/series/{imdbID}", handlers.GetSeries)
r.Get("/documentary/{imdbID}", handlers.GetDocumentary)
r.Get("/game/{imdbID}", handlers.GetGame)
r.Get("/franchise/{imdbID}", handlers.GetFranchise)
r.Put("/movie/{imdbID}", handlers.UpdateMovie)
r.Put("/series/{imdbID}", handlers.UpdateSeries)
r.Put("/documentary/{imdbID}", handlers.UpdateDocumentary)
r.Put("/game/{imdbID}", handlers.UpdateGame)
r.Put("/franchise/{imdbID}", handlers.UpdateFranchise)
r.Delete("/movie/{imdbID}", handlers.DeleteMovie)
r.Delete("/series/{imdbID}", handlers.DeleteSeries)
r.Delete("/documentary/{imdbID}", handlers.DeleteDocumentary)
r.Delete("/game/{imdbID}", handlers.DeleteGame)
r.Delete("/franchise/{imdbID}", handlers.DeleteFranchise)
r.Route("/omdb", func(r chi.Router) {
r.Get("/get/{imdbID}", handlers.OMDBGet)
r.Get("/seasons/{imdbID}", handlers.OMDBGetSeasons)
r.Get("/search/{search}", handlers.OMDBSearch)
r.Get("/search/{search}/{year}", handlers.OMDBSearch)
})
})
// static
r.Group(func(r chi.Router) {
r.Use(middlewares.Cache(24 * time.Hour))
handlers.ServeDir(r, "/js/*", http.Dir("./dist/js"))
handlers.ServeDir(r, "/css/*", http.Dir("./dist/css"))
handlers.ServeDir(r, "/fonts/*", http.Dir("./dist/fonts"))
handlers.ServeFile(r, "/favicon.ico*", "./dist/favicon.ico")
handlers.ServeFile(r, "/*", "./dist/index.html")
})
r.Group(func(r chi.Router) {
r.Get("/*", handlers.RootHandler)
})
http.Handle("/", r)
if conf.IsDev() {
log.Print(fmt.Sprintf("Dev server listening on port %d", 8182))
log.Fatal(http.ListenAndServe(":8182", r))
} else {
log.Fatal(http.ListenAndServe(":8080", r))
}
}