From 42316d3ead24c612ebc8ea2b92775d7541583952 Mon Sep 17 00:00:00 2001 From: ianwoolf Date: Thu, 6 Sep 2018 11:51:13 +0800 Subject: [PATCH] remove pathSuffix --- .gitignore | 1 + main.go | 11 ++--------- 2 files changed, 3 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..663e175 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +goproxy diff --git a/main.go b/main.go index d84836a..de0ced7 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "os/exec" + "path" "path/filepath" "strings" "time" @@ -40,7 +41,7 @@ func mainHandler(inner http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(os.Stdout, "goproxy: %s %s download %s\n", r.RemoteAddr, time.Now().Format("2006-01-02 15:04:05"), r.URL.Path) if _, err := os.Stat(filepath.Join(cacheDir, r.URL.Path)); err != nil { - suffix := pathSuffix(r.URL.Path) + suffix := path.Ext(r.URL.Path) if suffix == ".info" || suffix == ".mod" || suffix == ".zip" { mod := strings.Split(r.URL.Path, "/@v/") if len(mod) != 2 { @@ -62,9 +63,6 @@ func mainHandler(inner http.Handler) http.Handler { // ignore the error, incorrect tag may be given // forward to inner.ServeHTTP goGet(path, version, suffix, w, r) - } else { - ReturnBadRequest(w, fmt.Errorf("bad module path:%s", r.URL.Path)) - return } if strings.HasSuffix(r.URL.Path, "/@v/list") { w.Write([]byte("")) @@ -75,11 +73,6 @@ func mainHandler(inner http.Handler) http.Handler { }) } -func pathSuffix(path string) string { - suffixIndex := strings.LastIndex(path, ".") - return path[suffixIndex:] -} - func goGet(path, version, suffix string, w http.ResponseWriter, r *http.Request) error { cmd := exec.Command("go", "get", "-d", path+"@"+version) stdout, err := cmd.StdoutPipe()