remove pathSuffix

pull/11/head
ianwoolf 2018-09-06 11:51:13 +08:00 committed by kun
parent 9d4ae6116f
commit 42316d3ead
2 changed files with 3 additions and 9 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
goproxy

11
main.go
View File

@ -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()