-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
75 lines (62 loc) · 2.51 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
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"net/http"
"os"
handler "github.com/felipemarinho97/torrent-indexer/api"
"github.com/felipemarinho97/torrent-indexer/cache"
"github.com/felipemarinho97/torrent-indexer/monitoring"
"github.com/felipemarinho97/torrent-indexer/public"
"github.com/felipemarinho97/torrent-indexer/requester"
meilisearch "github.com/felipemarinho97/torrent-indexer/search"
"github.com/prometheus/client_golang/prometheus/promhttp"
str2duration "github.com/xhit/go-str2duration/v2"
)
func main() {
redis := cache.NewRedis()
searchIndex := meilisearch.NewSearchIndexer(os.Getenv("MEILISEARCH_ADDRESS"), os.Getenv("MEILISEARCH_KEY"), "torrents")
metrics := monitoring.NewMetrics()
metrics.Register()
flaresolverr := requester.NewFlareSolverr(os.Getenv("FLARESOLVERR_ADDRESS"), 60000)
req := requester.NewRequester(flaresolverr, redis)
// get shot-lived and long-lived cache expiration from env
shortLivedCacheExpiration, err := str2duration.ParseDuration(os.Getenv("SHORT_LIVED_CACHE_EXPIRATION"))
if err == nil {
fmt.Printf("Setting short-lived cache expiration to %s\n", shortLivedCacheExpiration)
req.SetShortLivedCacheExpiration(shortLivedCacheExpiration)
}
longLivedCacheExpiration, err := str2duration.ParseDuration(os.Getenv("LONG_LIVED_CACHE_EXPIRATION"))
if err == nil {
fmt.Printf("Setting long-lived cache expiration to %s\n", longLivedCacheExpiration)
redis.SetDefaultExpiration(longLivedCacheExpiration)
} else {
fmt.Println(err)
}
indexers := handler.NewIndexers(redis, metrics, req, searchIndex)
search := handler.NewMeilisearchHandler(searchIndex)
indexerMux := http.NewServeMux()
metricsMux := http.NewServeMux()
indexerMux.HandleFunc("/", handler.HandlerIndex)
indexerMux.HandleFunc("/indexers/comando_torrents", indexers.HandlerComandoIndexer)
indexerMux.HandleFunc("/indexers/torrent-dos-filmes", indexers.HandlerTorrentDosFilmesIndexer)
indexerMux.HandleFunc("/indexers/bludv", indexers.HandlerBluDVIndexer)
indexerMux.HandleFunc("/indexers/manual", indexers.HandlerManualIndexer)
indexerMux.HandleFunc("/search", search.SearchTorrentHandler)
indexerMux.Handle("/ui/", http.StripPrefix("/ui/", http.FileServer(http.FS(public.UIFiles))))
metricsMux.Handle("/metrics", promhttp.Handler())
go func() {
err := http.ListenAndServe(":8081", metricsMux)
if err != nil {
panic(err)
}
}()
port := os.Getenv("PORT")
if port == "" {
port = "7006"
}
fmt.Printf("Server listening on :%s\n", port)
err = http.ListenAndServe(":"+port, indexerMux)
if err != nil {
panic(err)
}
}