Add proper logging

This commit is contained in:
Ben Sarmiento
2023-11-05 01:23:41 +01:00
parent 1b116c2194
commit a9c71a3e93
11 changed files with 103 additions and 96 deletions

View File

@@ -1,7 +1,6 @@
package net
import (
"log"
"net/http"
"path"
"strings"
@@ -11,11 +10,15 @@ 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/debridmediamanager.com/zurg/pkg/logutil"
"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]) {
rlog := logutil.NewLogger()
log := rlog.Named("net")
mux.HandleFunc("/http/", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
@@ -30,7 +33,7 @@ func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentMana
universal.HandleHeadRequest(w, r, t, c, cache)
default:
log.Println("Method not implemented", r.Method)
log.Errorf("Request %s %s not supported yet", r.Method, r.URL.Path)
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
}
})
@@ -47,7 +50,7 @@ func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentMana
w.WriteHeader(http.StatusOK)
default:
log.Println("Method not implemented", r.Method, r.URL.Path)
log.Errorf("Request %s %s not supported yet", r.Method, r.URL.Path)
http.Error(w, "Method not implemented", http.StatusMethodNotAllowed)
}
})