mirror of https://github.com/goproxyio/goproxy
parent
fa6fae8849
commit
3d49ac1020
|
@ -5,3 +5,5 @@ cacheDir/*
|
|||
bin/*
|
||||
|
||||
internal/
|
||||
pkg/*
|
||||
!pkg/proxy
|
||||
|
|
|
@ -55,7 +55,7 @@ func NewProxy(cache string) http.Handler {
|
|||
realMod, err := getQuery(info.Version.Path, info.Version.Version)
|
||||
if err != nil {
|
||||
errLogger.Printf("goproxy: lookup %s@%s get err %s", info.Path, info.Version.Version, err)
|
||||
ReturnBadRequest(w, err)
|
||||
ReturnNotFound(w, err)
|
||||
return
|
||||
}
|
||||
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
|
||||
// TODO(hxzhao527): check whether InfoFile have a bug?
|
||||
errLogger.Printf("goproxy: fetch info %s@%s get err %s", info.Path, info.Version.Version, err)
|
||||
ReturnBadRequest(w, err)
|
||||
ReturnNotFound(w, err)
|
||||
} else {
|
||||
ReturnJsonData(w, revInfo)
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ func NewProxy(cache string) http.Handler {
|
|||
{
|
||||
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)
|
||||
ReturnBadRequest(w, err)
|
||||
ReturnNotFound(w, err)
|
||||
} else {
|
||||
http.ServeFile(w, r, modFile)
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func NewProxy(cache string) http.Handler {
|
|||
mod := module.Version{Path: realMod.Path, Version: realMod.Version}
|
||||
if zipFile, err := modfetch.DownloadZip(mod); err != nil {
|
||||
errLogger.Printf("goproxy: download zip %s@%s get err %s", info.Path, info.Version.Version, err)
|
||||
ReturnBadRequest(w, err)
|
||||
ReturnNotFound(w, err)
|
||||
} else {
|
||||
http.ServeFile(w, r, zipFile)
|
||||
}
|
||||
|
@ -101,22 +101,21 @@ func NewProxy(cache string) http.Handler {
|
|||
{
|
||||
repo, err := modfetch.Lookup(info.Path)
|
||||
if err != nil {
|
||||
errLogger.Printf("goproxy: lookup failed: %v", err)
|
||||
ReturnInternalServerError(w, err)
|
||||
ReturnNotFound(w, err)
|
||||
return
|
||||
}
|
||||
switch suf {
|
||||
case "/@v/list":
|
||||
modPath := strings.Trim(strings.TrimSuffix(r.URL.Path, "/@v/list"), "/")
|
||||
modPath, err := module.DecodePath(modPath)
|
||||
if err != nil {
|
||||
ReturnInternalServerError(w, err)
|
||||
if err != nil {
|
||||
ReturnNotFound(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
modload.LoadBuildList()
|
||||
mods := modload.ListModules([]string{modPath + "@latest"}, false, true)
|
||||
|
||||
|
||||
data := []byte(strings.Join(mods[0].Versions, "\n") + "\n")
|
||||
if len(data) == 1 {
|
||||
data = nil
|
||||
|
@ -126,7 +125,7 @@ func NewProxy(cache string) http.Handler {
|
|||
case "/@latest":
|
||||
rev, err := repo.Stat("latest")
|
||||
if err != nil {
|
||||
errLogger.Printf("latest failed: %v", err)
|
||||
ReturnNotFound(w, err)
|
||||
return
|
||||
}
|
||||
ReturnJsonData(w, rev)
|
||||
|
|
|
@ -24,6 +24,13 @@ func ReturnBadRequest(w http.ResponseWriter, err error) {
|
|||
_, _ = 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) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(data)
|
||||
|
@ -32,7 +39,7 @@ func ReturnSuccess(w http.ResponseWriter, data []byte) {
|
|||
func ReturnJsonData(w http.ResponseWriter, data interface{}) {
|
||||
js, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
ReturnInternalServerError(w, err)
|
||||
ReturnNotFound(w, err)
|
||||
} else {
|
||||
ReturnSuccess(w, js)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue