fix go get faild in go1.13beta1

v1 v1.0.0
kun 2019-07-11 11:04:03 +08:00
parent fa6fae8849
commit 3d49ac1020
3 changed files with 19 additions and 11 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ cacheDir/*
bin/* bin/*
internal/ internal/
pkg/*
!pkg/proxy

View File

@ -55,7 +55,7 @@ func NewProxy(cache string) http.Handler {
realMod, err := getQuery(info.Version.Path, info.Version.Version) realMod, err := getQuery(info.Version.Path, info.Version.Version)
if err != nil { if err != nil {
errLogger.Printf("goproxy: lookup %s@%s get err %s", info.Path, info.Version.Version, err) errLogger.Printf("goproxy: lookup %s@%s get err %s", info.Path, info.Version.Version, err)
ReturnBadRequest(w, err) ReturnNotFound(w, err)
return return
} }
if realMod.Path != info.Version.Path { if realMod.Path != info.Version.Path {
@ -70,7 +70,7 @@ func NewProxy(cache string) http.Handler {
// use Stat instead of InfoFile, because when query-version is master, no infoFile here, maybe bug of go // use Stat instead of InfoFile, because when query-version is master, no infoFile here, maybe bug of go
// TODO(hxzhao527): check whether InfoFile have a bug? // TODO(hxzhao527): check whether InfoFile have a bug?
errLogger.Printf("goproxy: fetch info %s@%s get err %s", info.Path, info.Version.Version, err) errLogger.Printf("goproxy: fetch info %s@%s get err %s", info.Path, info.Version.Version, err)
ReturnBadRequest(w, err) ReturnNotFound(w, err)
} else { } else {
ReturnJsonData(w, revInfo) ReturnJsonData(w, revInfo)
} }
@ -79,7 +79,7 @@ func NewProxy(cache string) http.Handler {
{ {
if modFile, err := modfetch.GoModFile(realMod.Path, realMod.Version); err != nil { if modFile, err := modfetch.GoModFile(realMod.Path, realMod.Version); err != nil {
errLogger.Printf("goproxy: fetch modfile %s@%s get err %s", info.Path, info.Version.Version, err) errLogger.Printf("goproxy: fetch modfile %s@%s get err %s", info.Path, info.Version.Version, err)
ReturnBadRequest(w, err) ReturnNotFound(w, err)
} else { } else {
http.ServeFile(w, r, modFile) http.ServeFile(w, r, modFile)
} }
@ -89,7 +89,7 @@ func NewProxy(cache string) http.Handler {
mod := module.Version{Path: realMod.Path, Version: realMod.Version} mod := module.Version{Path: realMod.Path, Version: realMod.Version}
if zipFile, err := modfetch.DownloadZip(mod); err != nil { if zipFile, err := modfetch.DownloadZip(mod); err != nil {
errLogger.Printf("goproxy: download zip %s@%s get err %s", info.Path, info.Version.Version, err) errLogger.Printf("goproxy: download zip %s@%s get err %s", info.Path, info.Version.Version, err)
ReturnBadRequest(w, err) ReturnNotFound(w, err)
} else { } else {
http.ServeFile(w, r, zipFile) http.ServeFile(w, r, zipFile)
} }
@ -101,22 +101,21 @@ func NewProxy(cache string) http.Handler {
{ {
repo, err := modfetch.Lookup(info.Path) repo, err := modfetch.Lookup(info.Path)
if err != nil { if err != nil {
errLogger.Printf("goproxy: lookup failed: %v", err) ReturnNotFound(w, err)
ReturnInternalServerError(w, err)
return return
} }
switch suf { switch suf {
case "/@v/list": case "/@v/list":
modPath := strings.Trim(strings.TrimSuffix(r.URL.Path, "/@v/list"), "/") modPath := strings.Trim(strings.TrimSuffix(r.URL.Path, "/@v/list"), "/")
modPath, err := module.DecodePath(modPath) modPath, err := module.DecodePath(modPath)
if err != nil { if err != nil {
ReturnInternalServerError(w, err) ReturnNotFound(w, err)
return return
} }
modload.LoadBuildList() modload.LoadBuildList()
mods := modload.ListModules([]string{modPath + "@latest"}, false, true) mods := modload.ListModules([]string{modPath + "@latest"}, false, true)
data := []byte(strings.Join(mods[0].Versions, "\n") + "\n") data := []byte(strings.Join(mods[0].Versions, "\n") + "\n")
if len(data) == 1 { if len(data) == 1 {
data = nil data = nil
@ -126,7 +125,7 @@ func NewProxy(cache string) http.Handler {
case "/@latest": case "/@latest":
rev, err := repo.Stat("latest") rev, err := repo.Stat("latest")
if err != nil { if err != nil {
errLogger.Printf("latest failed: %v", err) ReturnNotFound(w, err)
return return
} }
ReturnJsonData(w, rev) ReturnJsonData(w, rev)

View File

@ -24,6 +24,13 @@ func ReturnBadRequest(w http.ResponseWriter, err error) {
_, _ = w.Write([]byte(msg)) _, _ = w.Write([]byte(msg))
} }
func ReturnNotFound(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusNotFound)
msg := fmt.Sprintf("%v", err)
errLogger.Printf("goproxy: %s\n", msg)
_, _ = w.Write([]byte(msg))
}
func ReturnSuccess(w http.ResponseWriter, data []byte) { func ReturnSuccess(w http.ResponseWriter, data []byte) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
_, _ = w.Write(data) _, _ = w.Write(data)
@ -32,7 +39,7 @@ func ReturnSuccess(w http.ResponseWriter, data []byte) {
func ReturnJsonData(w http.ResponseWriter, data interface{}) { func ReturnJsonData(w http.ResponseWriter, data interface{}) {
js, err := json.Marshal(data) js, err := json.Marshal(data)
if err != nil { if err != nil {
ReturnInternalServerError(w, err) ReturnNotFound(w, err)
} else { } else {
ReturnSuccess(w, js) ReturnSuccess(w, js)
} }