added potential log levels to #log comments

This commit is contained in:
2026-05-03 21:08:03 -06:00
parent 46c2b9a2ff
commit 2edab08448
4 changed files with 18 additions and 17 deletions
+8 -9
View File
@@ -14,14 +14,14 @@ import (
func (s *Server) handlePackage(w http.ResponseWriter, req *http.Request) {
// most mirrors don't have a *db.sig so we 404 it here instead of spamming the mirror
// db files are not signed so we ignore as to not spam mirrors
if strings.HasSuffix(req.PathValue("file"), ".db.sig") {
w.WriteHeader(http.StatusNotFound)
return
}
// record the useragent from requestor
// #log
// #log level debug
log.Printf("Requestors UA: %s", req.Header.Get("User-Agent"))
// build file paths from the request, they follow archlinux repo
@@ -29,18 +29,17 @@ func (s *Server) handlePackage(w http.ResponseWriter, req *http.Request) {
repo := req.PathValue("repo")
arch := req.PathValue("arch")
file := req.PathValue("file")
repoPath := filepath.Join(repo, "os", arch, file) //path from mirror root to pkg or db file
repoPath := filepath.Join(repo, "os", arch, file) //path from mirror root to requested file
cachedFile, err := s.c.Fetch(repoPath)
if err != nil {
var upstreamErr *cache.UpstreamError
if errors.As(err, &upstreamErr) {
// #log
log.Printf("upstream error: %v", err)
if upstreamErr, ok := errors.AsType[*cache.UpstreamError](err); ok {
// #log level warn
log.Printf("upstream Error: %v", upstreamErr.Error())
http.Error(w, "Not found upstream", upstreamErr.StatusCode)
return
}
// #log
// #log level warn
log.Printf("fetch error: %v", err)
http.Error(w, "Failed to fetch from upstream", http.StatusBadGateway)
return
@@ -52,7 +51,7 @@ func (s *Server) handlePackage(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Length", strconv.FormatInt(cachedFile.Size, 10))
_, err = io.Copy(w, cachedFile.Reader)
if err != nil {
// #log
// #log error
log.Printf("error streaming file to client: %v", err)
}
+3 -1
View File
@@ -15,7 +15,7 @@ func (c *Cache) Fetch(relPath string) (*CacheFile, error) {
// fetch file from upstream
_, err, _ = c.sf.Do(relPath, func() (any, error) {
// #log
// #log info
log.Print("calling fetch")
return nil, c.fetch(relPath)
})
@@ -46,6 +46,8 @@ func (c *Cache) fetch(relPath string) error {
if err == nil {
break
}
// #log warn or info
log.Printf("mirror %s returned %v", url, err)
}
if err != nil {
return err
+4 -4
View File
@@ -13,13 +13,13 @@ func (c *Cache) nextMirror() string {
}
func downloadToDisk(url, destPath string, c http.Client) error {
// #log
// #log info
log.Printf("fetching %v", url)
// set the user agent
req, err := http.NewRequest("GET", url, nil)
if err != nil {
// #log
// #log info
log.Printf("failed to create request: %v", err)
return &UpstreamError{StatusCode: http.StatusInternalServerError}
}
@@ -27,12 +27,12 @@ func downloadToDisk(url, destPath string, c http.Client) error {
resp, err := c.Do(req)
if err != nil {
// #log
// #log warn
log.Printf("error fetching %s: %v", url, err)
return err
}
if resp.StatusCode != 200 {
// #log
// #log info
log.Printf("GET %s returned %d", url, resp.StatusCode)
return &UpstreamError{StatusCode: resp.StatusCode}
}
+3 -3
View File
@@ -25,7 +25,7 @@ func main() {
cfg, err := ReadConfig(configPath)
if err != nil {
// #log
// #log error
log.Fatal(err)
}
@@ -37,7 +37,7 @@ func main() {
mux.HandleFunc("POST /api/refresh", srv.handlerRefresh)
if err := srv.c.Refresh(); err != nil {
// #log
// #log error
log.Fatal(err)
}
@@ -46,7 +46,7 @@ func main() {
Handler: mux,
}
// #log
// #log error
log.Printf("serving pkgstash root: %v on port: %v", cfg.CacheRoot, cfg.Port)
log.Fatal(httpServe.ListenAndServe())