Only return the meta for requested package

the go tool currenty has a pathology where it mistakingly claims it
can't clone a repo because it checks prefix by bytes, not by splitting
the path on slash.

Once https://github.com/golang/go/issues/15947 comes out (go1.8) then go
tools will be able to handle being provided with valid but overlapping
packages.

For now though we'll just return meta for the requested package.

Change-Id: Ie5026e7d5c1377ff7d2c2140b21f9b745af69764
This commit is contained in:
sm
2016-06-05 22:41:56 -07:00
parent 5458745af9
commit 295a7c3840
3 changed files with 75 additions and 4 deletions
+14 -4
View File
@@ -54,11 +54,20 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
http.Redirect(w, req, prefix["static"], http.StatusTemporaryRedirect)
return
}
fmt.Fprintf(w, "<!DOCTYPE html>\n<html><head>\n")
for _, p := range s.db.Pkgs() {
fmt.Fprintf(w, "%s\n", p)
if req.URL.Path == "/" {
fmt.Fprintf(w, "<!DOCTYPE html>\n<html><head>\n")
for _, p := range s.db.Pkgs() {
fmt.Fprintf(w, "%s\n", p)
}
fmt.Fprintf(w, "</head>\n<body><p>go tool metadata in head</p></body>\n</html>\n")
} else {
p, err := s.db.Package(req.Host + req.URL.Path)
if err := verrors.ToHTTP(err); err != nil {
http.Error(w, err.Message, err.Code)
return
}
fmt.Fprintf(w, "<!DOCTYPE html>\n<html><head>\n%s\n</head>\n<body><p>go tool metadata in head</p></body>\n</html>\n", p)
}
fmt.Fprintf(w, "</head>\n<body><p>go tool metadata in head</p></body>\n</html>\n")
return
}
@@ -207,6 +216,7 @@ func (s *Server) forgot(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-type", "application/json")
json.NewEncoder(w).Encode(resp)
}
func (s *Server) pkgs(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-type", "application/json")
json.NewEncoder(w).Encode(s.db.Pkgs())