Remove unnecessary passing of cache by ref
This commit is contained in:
@@ -73,7 +73,7 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
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())
|
addr := fmt.Sprintf("%s:%s", config.GetHost(), config.GetPort())
|
||||||
server := &http.Server{Addr: addr, Handler: mux}
|
server := &http.Server{Addr: addr, Handler: mux}
|
||||||
|
|||||||
@@ -9,11 +9,10 @@ import (
|
|||||||
|
|
||||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||||
"github.com/debridmediamanager.com/zurg/pkg/dav"
|
"github.com/debridmediamanager.com/zurg/pkg/dav"
|
||||||
"github.com/dgraph-io/ristretto"
|
|
||||||
"go.uber.org/zap"
|
"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)
|
requestPath := path.Clean(r.URL.Path)
|
||||||
|
|
||||||
var output *string
|
var output *string
|
||||||
|
|||||||
@@ -10,11 +10,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||||
"github.com/dgraph-io/ristretto"
|
|
||||||
"go.uber.org/zap"
|
"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)
|
requestPath := path.Clean(r.URL.Path)
|
||||||
|
|
||||||
var output *string
|
var output *string
|
||||||
|
|||||||
@@ -10,20 +10,19 @@ import (
|
|||||||
intHttp "github.com/debridmediamanager.com/zurg/internal/http"
|
intHttp "github.com/debridmediamanager.com/zurg/internal/http"
|
||||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||||
"github.com/debridmediamanager.com/zurg/internal/universal"
|
"github.com/debridmediamanager.com/zurg/internal/universal"
|
||||||
"github.com/dgraph-io/ristretto"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Router creates a WebDAV router
|
// 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) {
|
mux.HandleFunc("/http/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
requestPath := path.Clean(r.URL.Path)
|
requestPath := path.Clean(r.URL.Path)
|
||||||
if countNonEmptySegments(strings.Split(requestPath, "/")) > 3 {
|
if countNonEmptySegments(strings.Split(requestPath, "/")) > 3 {
|
||||||
getfile.HandleGetRequest(w, r, t, c, cache, log)
|
getfile.HandleGetRequest(w, r, t, c, log)
|
||||||
} else {
|
} else {
|
||||||
intHttp.HandleDirectoryListing(w, r, t, cache, log)
|
intHttp.HandleDirectoryListing(w, r, t, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
case http.MethodHead:
|
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) {
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "PROPFIND":
|
case "PROPFIND":
|
||||||
dav.HandlePropfindRequest(w, r, t, cache, log)
|
dav.HandlePropfindRequest(w, r, t, log)
|
||||||
|
|
||||||
case http.MethodDelete:
|
case http.MethodDelete:
|
||||||
dav.HandleDeleteRequest(w, r, t, log)
|
dav.HandleDeleteRequest(w, r, t, log)
|
||||||
|
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
getfile.HandleGetRequest(w, r, t, c, cache, log)
|
getfile.HandleGetRequest(w, r, t, c, log)
|
||||||
|
|
||||||
case http.MethodOptions:
|
case http.MethodOptions:
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import (
|
|||||||
intHttp "github.com/debridmediamanager.com/zurg/internal/http"
|
intHttp "github.com/debridmediamanager.com/zurg/internal/http"
|
||||||
intTor "github.com/debridmediamanager.com/zurg/internal/torrent"
|
intTor "github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||||
zurghttp "github.com/debridmediamanager.com/zurg/pkg/http"
|
zurghttp "github.com/debridmediamanager.com/zurg/pkg/http"
|
||||||
"github.com/dgraph-io/ristretto"
|
|
||||||
"go.uber.org/zap"
|
"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
|
// 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)
|
requestPath := path.Clean(r.URL.Path)
|
||||||
isDav := true
|
isDav := true
|
||||||
if strings.Contains(requestPath, "/http") {
|
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 there are less than 3 segments, return an error or adjust as needed
|
||||||
if len(segments) <= 3 {
|
if len(segments) <= 3 {
|
||||||
if isDav {
|
if isDav {
|
||||||
dav.HandlePropfindRequest(w, r, t, cache, log)
|
dav.HandlePropfindRequest(w, r, t, log)
|
||||||
} else {
|
} else {
|
||||||
intHttp.HandleDirectoryListing(w, r, t, cache, log)
|
intHttp.HandleDirectoryListing(w, r, t, log)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user