From 993982441cf0184aabed6af4fd671001ddd05708 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 11 Dec 2021 18:03:25 -0600 Subject: [PATCH] remove dead code, handle errors better --- handler.go | 44 +++----------------------------------------- 1 file changed, 3 insertions(+), 41 deletions(-) diff --git a/handler.go b/handler.go index 10c9441..c059176 100644 --- a/handler.go +++ b/handler.go @@ -141,46 +141,6 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) w.Write([]byte("not found")) return - - // switch r.URL.Path { - // case "/fart": - // // Step 1: a request comes in at orel.li. This page contains a meta tag - // // indicating where the package contents may be found, and which backend - // // is serving the package. - // serveFile(w, "meta/fart/root.html") - // case "/modules/orel.li/fart/@v/list": - // // Step 2: list all of the versions for the package. Versions may be - // // available but unlisted. - // serveFile(w, "meta/fart/version-list") - // case "/modules/orel.li/fart/@latest", - // "/modules/orel.li/fart/@v/v0.0.3.info": - // // Step 3: get info for the version, which is just a timestamp at the - // // moment. - // e := json.NewEncoder(w) - // e.Encode(versionInfo{ - // Version: "v0.0.3", - // Time: time.Now(), - // }) - // case "/modules/orel.li/fart/@v/v0.0.3.mod": - // // Step 4: retrieve the modfile for the package, informing go mod of - // // any transitive dependencies. - // serveFile(w, "meta/fart/modfile") - // case "/modules/orel.li/fart/@v/v0.0.3.zip": - // // Step 5: retrieve the source code contents for a package, as a - // // specially-formatted zip file. - // err := zip.CreateFromDir(w, module.Version{ - // Path: "orel.li/fart", - // Version: "v0.0.3", - // }, "/home/jorelli/mir/modules/orel.li/fart") - // if err != nil { - // log_error.Printf("zip error: %v", err) - // } - // case "/": - // w.WriteHeader(http.StatusOK) - // default: - // w.WriteHeader(http.StatusNotFound) - // w.Write([]byte("not found")) - // } } // locate searches our module root for a given modpath @@ -334,7 +294,9 @@ func (h handler) modfile(modpath, modversion string, w http.ResponseWriter, r *h } defer f.Close() - io.Copy(w, f) + if _, err := io.Copy(w, f); err != nil { + log_error.Printf("error copying modfile contents for %s version %s: %v", modpath, modversion, err) + } } // zipfile serves the $base/$module/@v/$version.zip endpoint