Use new router

This commit is contained in:
Ben Sarmiento
2023-11-30 22:46:29 +01:00
parent 5472f7d08d
commit 0ad879066e
13 changed files with 311 additions and 384 deletions

View File

@@ -2,18 +2,19 @@ package internal
import (
"fmt"
"net/http"
netHttp "net/http"
"os"
"github.com/debridmediamanager/zurg/internal/config"
"github.com/debridmediamanager/zurg/internal/net"
"github.com/debridmediamanager/zurg/internal/router"
"github.com/debridmediamanager/zurg/internal/torrent"
"github.com/debridmediamanager/zurg/internal/universal"
zurghttp "github.com/debridmediamanager/zurg/pkg/http"
"github.com/debridmediamanager/zurg/pkg/http"
"github.com/debridmediamanager/zurg/pkg/logutil"
"github.com/debridmediamanager/zurg/pkg/realdebrid"
"github.com/debridmediamanager/zurg/pkg/utils"
"github.com/dgraph-io/ristretto"
"github.com/julienschmidt/httprouter"
"github.com/panjf2000/ants/v2"
)
@@ -27,7 +28,7 @@ func MainApp(configPath string) {
os.Exit(1)
}
apiClient := zurghttp.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), config.GetRealDebridTimeout(), config, log.Named("httpclient"))
apiClient := http.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), config.GetRealDebridTimeout(), config, log.Named("httpclient"))
rd := realdebrid.NewRealDebrid(apiClient, log.Named("realdebrid"))
@@ -52,17 +53,17 @@ func MainApp(configPath string) {
torrentMgr := torrent.NewTorrentManager(config, rd, p, cache, log.Named("manager"))
downloadClient := zurghttp.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), 0, config, log.Named("dlclient"))
downloadClient := http.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), 0, config, log.Named("dlclient"))
getfile := universal.NewGetFile(downloadClient)
mux := http.NewServeMux()
net.Router(mux, getfile, config, torrentMgr, log.Named("net"))
handler := httprouter.New()
handler.RedirectTrailingSlash = false
handler.RedirectFixedPath = true
router.ApplyRouteTable(handler, getfile, torrentMgr, config, log.Named("router"))
addr := fmt.Sprintf("%s:%s", config.GetHost(), config.GetPort())
server := &http.Server{Addr: addr, Handler: mux}
zurglog.Infof("Starting server on %s", addr)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
if err := netHttp.ListenAndServe(addr, handler); err != nil && err != netHttp.ErrServerClosed {
zurglog.Errorf("Failed to start server: %v", err)
os.Exit(1)
}