automatic support for go get on deep subpackages
This commit is contained in:
parent
28e7e769b1
commit
200cf0ee2c
13
main.go
13
main.go
@ -342,6 +342,19 @@ func (this *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
r.URL.Path = r.URL.Path[8:]
|
r.URL.Path = r.URL.Path[8:]
|
||||||
http.FileServer(http.Dir(`static`)).ServeHTTP(w, r)
|
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 {
|
} else {
|
||||||
http.Error(w, "not found", 404)
|
http.Error(w, "not found", 404)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user