Files
zurg/internal/dav/router.go
Ben Sarmiento 6eccba394c Add caching
2023-10-22 13:29:41 +02:00

31 lines
788 B
Go

package dav
import (
"log"
"net/http"
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/hashicorp/golang-lru/v2/expirable"
)
// Router creates a WebDAV router
func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentManager, cache *expirable.LRU[string, string]) {
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PROPFIND":
HandlePropfindRequest(w, r, t, c, cache)
case http.MethodGet:
HandleGetRequest(w, r, t, c, cache)
case http.MethodOptions:
w.WriteHeader(http.StatusOK)
default:
log.Println("Method not implemented", r.Method)
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
}
})
}