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