diff --git a/main.go b/main.go index e12884a..ec69fab 100644 --- a/main.go +++ b/main.go @@ -342,6 +342,19 @@ func (this *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) { r.URL.Path = r.URL.Path[8:] http.FileServer(http.Dir(`static`)).ServeHTTP(w, r) + } else if r.URL.Query().Get("go-get") == "1" { + // This wasn't one of our standard `/repo` paths, but there is the ?go-get=1 parameter + // It must be a subpackage request + // We can't serve the proper go-import meta tag immediately because + // we haven't looked up the go.mod yet. Just redirect to the root + // package - `go get` will follow redirects and the resulting meta tag is correct + + slashParts := strings.SplitN(r.URL.Path, `/`, 3) // len === 3 is guaranteed from earlier if cases + + w.Header().Set(`Location`, `/`+slashParts[1]) + w.WriteHeader(301) + return + } else { http.Error(w, "not found", 404) }