From 81aba99168ad82f83079000841597252ebafebb3 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Wed, 29 Nov 2023 00:48:08 +0100 Subject: [PATCH] Remove unnecessary passing of cache by ref --- cmd/zurg/main.go | 2 +- internal/dav/listing.go | 3 +-- internal/http/listing.go | 3 +-- internal/net/router.go | 11 +++++------ internal/universal/get.go | 7 +++---- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/cmd/zurg/main.go b/cmd/zurg/main.go index dfae331..502ed51 100644 --- a/cmd/zurg/main.go +++ b/cmd/zurg/main.go @@ -73,7 +73,7 @@ func main() { }() mux := http.NewServeMux() - net.Router(mux, getfile, config, torrentMgr, cache, log.Named("net")) + net.Router(mux, getfile, config, torrentMgr, log.Named("net")) addr := fmt.Sprintf("%s:%s", config.GetHost(), config.GetPort()) server := &http.Server{Addr: addr, Handler: mux} diff --git a/internal/dav/listing.go b/internal/dav/listing.go index cf6db11..cab207d 100644 --- a/internal/dav/listing.go +++ b/internal/dav/listing.go @@ -9,11 +9,10 @@ import ( "github.com/debridmediamanager.com/zurg/internal/torrent" "github.com/debridmediamanager.com/zurg/pkg/dav" - "github.com/dgraph-io/ristretto" "go.uber.org/zap" ) -func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, cache *ristretto.Cache, log *zap.SugaredLogger) { +func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, log *zap.SugaredLogger) { requestPath := path.Clean(r.URL.Path) var output *string diff --git a/internal/http/listing.go b/internal/http/listing.go index 44c6708..b51ed39 100644 --- a/internal/http/listing.go +++ b/internal/http/listing.go @@ -10,11 +10,10 @@ import ( "strings" "github.com/debridmediamanager.com/zurg/internal/torrent" - "github.com/dgraph-io/ristretto" "go.uber.org/zap" ) -func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, cache *ristretto.Cache, log *zap.SugaredLogger) { +func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, log *zap.SugaredLogger) { requestPath := path.Clean(r.URL.Path) var output *string diff --git a/internal/net/router.go b/internal/net/router.go index e56bdd1..4680f81 100644 --- a/internal/net/router.go +++ b/internal/net/router.go @@ -10,20 +10,19 @@ import ( intHttp "github.com/debridmediamanager.com/zurg/internal/http" "github.com/debridmediamanager.com/zurg/internal/torrent" "github.com/debridmediamanager.com/zurg/internal/universal" - "github.com/dgraph-io/ristretto" "go.uber.org/zap" ) // Router creates a WebDAV router -func Router(mux *http.ServeMux, getfile *universal.GetFile, c config.ConfigInterface, t *torrent.TorrentManager, cache *ristretto.Cache, log *zap.SugaredLogger) { +func Router(mux *http.ServeMux, getfile *universal.GetFile, c config.ConfigInterface, t *torrent.TorrentManager, log *zap.SugaredLogger) { mux.HandleFunc("/http/", func(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodGet: requestPath := path.Clean(r.URL.Path) if countNonEmptySegments(strings.Split(requestPath, "/")) > 3 { - getfile.HandleGetRequest(w, r, t, c, cache, log) + getfile.HandleGetRequest(w, r, t, c, log) } else { - intHttp.HandleDirectoryListing(w, r, t, cache, log) + intHttp.HandleDirectoryListing(w, r, t, log) } case http.MethodHead: @@ -38,13 +37,13 @@ func Router(mux *http.ServeMux, getfile *universal.GetFile, c config.ConfigInter mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { switch r.Method { case "PROPFIND": - dav.HandlePropfindRequest(w, r, t, cache, log) + dav.HandlePropfindRequest(w, r, t, log) case http.MethodDelete: dav.HandleDeleteRequest(w, r, t, log) case http.MethodGet: - getfile.HandleGetRequest(w, r, t, c, cache, log) + getfile.HandleGetRequest(w, r, t, c, log) case http.MethodOptions: w.WriteHeader(http.StatusOK) diff --git a/internal/universal/get.go b/internal/universal/get.go index 21ab962..ab11a78 100644 --- a/internal/universal/get.go +++ b/internal/universal/get.go @@ -14,7 +14,6 @@ import ( intHttp "github.com/debridmediamanager.com/zurg/internal/http" intTor "github.com/debridmediamanager.com/zurg/internal/torrent" zurghttp "github.com/debridmediamanager.com/zurg/pkg/http" - "github.com/dgraph-io/ristretto" "go.uber.org/zap" ) @@ -27,7 +26,7 @@ func NewGetFile(client *zurghttp.HTTPClient) *GetFile { } // HandleGetRequest handles a GET request universally for both WebDAV and HTTP -func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *intTor.TorrentManager, c config.ConfigInterface, cache *ristretto.Cache, log *zap.SugaredLogger) { +func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *intTor.TorrentManager, c config.ConfigInterface, log *zap.SugaredLogger) { requestPath := path.Clean(r.URL.Path) isDav := true if strings.Contains(requestPath, "/http") { @@ -41,9 +40,9 @@ func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *i // If there are less than 3 segments, return an error or adjust as needed if len(segments) <= 3 { if isDav { - dav.HandlePropfindRequest(w, r, t, cache, log) + dav.HandlePropfindRequest(w, r, t, log) } else { - intHttp.HandleDirectoryListing(w, r, t, cache, log) + intHttp.HandleDirectoryListing(w, r, t, log) } return }