added #log at all points wherer log pkg is used
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
- ~add a UA to get client, some servers are 403 the default go client~
|
||||
- Add better logging for errors, filename more deatail
|
||||
- Solve timeout issue large pkgs, maybe stream
|
||||
- ~Move project to github as primary~
|
||||
- implement streaming
|
||||
|
||||
- Complete testing
|
||||
- Deployment(PKGBUILD, bootstrap script?)
|
||||
@@ -10,6 +8,9 @@
|
||||
- Add chi for mux
|
||||
- Build server/tool
|
||||
- ~retry on failed fetch~
|
||||
- ~Solve timeout issue large pkgs~
|
||||
- ~Move project to github as primary~
|
||||
- ~add a UA to get client, some servers are 403 the default go client~
|
||||
- ~Basic config Testing~
|
||||
- ~flag for loading non default config~
|
||||
- ~add cli option for config location~
|
||||
|
||||
@@ -11,6 +11,7 @@ func (s *Server) handlerRefresh(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
if err := s.c.Refresh(); err != nil {
|
||||
// #log
|
||||
log.Printf("refresh failed: %v", err)
|
||||
http.Error(w, "refresh failed", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -21,6 +21,7 @@ func (s *Server) handlePackage(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
// record the useragent from requestor
|
||||
// #log
|
||||
log.Printf("Requestors UA: %s", req.Header.Get("User-Agent"))
|
||||
|
||||
// build file paths from the request, they follow archlinux repo
|
||||
@@ -34,10 +35,12 @@ func (s *Server) handlePackage(w http.ResponseWriter, req *http.Request) {
|
||||
if err != nil {
|
||||
var upstreamErr *cache.UpstreamError
|
||||
if errors.As(err, &upstreamErr) {
|
||||
// #log
|
||||
log.Printf("upstream error: %v", err)
|
||||
http.Error(w, "Not found upstream", upstreamErr.StatusCode)
|
||||
return
|
||||
}
|
||||
// #log
|
||||
log.Printf("fetch error: %v", err)
|
||||
http.Error(w, "Failed to fetch from upstream", http.StatusBadGateway)
|
||||
return
|
||||
@@ -49,6 +52,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.Printf("error streaming file to client: %v", err)
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -15,6 +15,7 @@ func (c *Cache) Fetch(relPath string) (*CacheFile, error) {
|
||||
|
||||
// fetch file from upstream
|
||||
_, err, _ = c.sf.Do(relPath, func() (any, error) {
|
||||
// #log
|
||||
log.Print("calling fetch")
|
||||
return nil, c.fetch(relPath)
|
||||
})
|
||||
|
||||
Vendored
+4
@@ -13,11 +13,13 @@ func (c *Cache) nextMirror() string {
|
||||
}
|
||||
|
||||
func downloadToDisk(url, destPath string, c http.Client) error {
|
||||
// #log
|
||||
log.Printf("fetching %v", url)
|
||||
|
||||
// set the user agent
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
// #log
|
||||
log.Printf("failed to create request: %v", err)
|
||||
return &UpstreamError{StatusCode: http.StatusInternalServerError}
|
||||
}
|
||||
@@ -25,10 +27,12 @@ func downloadToDisk(url, destPath string, c http.Client) error {
|
||||
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
// #log
|
||||
log.Printf("error fetching %s: %v", url, err)
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
// #log
|
||||
log.Printf("GET %s returned %d", url, resp.StatusCode)
|
||||
return &UpstreamError{StatusCode: resp.StatusCode}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ func main() {
|
||||
|
||||
cfg, err := ReadConfig(configPath)
|
||||
if err != nil {
|
||||
// #log
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -36,6 +37,7 @@ func main() {
|
||||
mux.HandleFunc("POST /api/refresh", srv.handlerRefresh)
|
||||
|
||||
if err := srv.c.Refresh(); err != nil {
|
||||
// #log
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -44,6 +46,7 @@ func main() {
|
||||
Handler: mux,
|
||||
}
|
||||
|
||||
// #log
|
||||
log.Printf("serving pkgstash root: %v on port: %v", cfg.CacheRoot, cfg.Port)
|
||||
log.Fatal(httpServe.ListenAndServe())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user