Detailed changes
@@ -32,6 +32,7 @@ func NewContextHandler(ctx context.Context) func(http.Handler) http.Handler {
ctx = db.WithContext(ctx, dbx)
ctx = store.WithContext(ctx, datastore)
r = r.WithContext(ctx)
+
next.ServeHTTP(w, r)
})
}
@@ -72,7 +72,7 @@ var (
}, []string{"repo", "file"})
)
-func withParams(h http.Handler) http.Handler {
+func withParams(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
cfg := config.FromContext(ctx)
@@ -97,7 +97,8 @@ func withParams(h http.Handler) http.Handler {
// Add repo suffix (.git)
r.URL.Path = fmt.Sprintf("%s.git/%s", repo, vars["file"])
r = mux.SetURLVars(r, vars)
- h.ServeHTTP(w, r)
+
+ next.ServeHTTP(w, r)
})
}
@@ -111,7 +112,7 @@ func GitController(_ context.Context, r *mux.Router) {
}
// Handle go-get
- r.Handle(basePrefix, withParams(withAccess(GoGetHandler{}))).Methods(http.MethodGet)
+ r.Handle(basePrefix, withParams(withAccess(http.HandlerFunc(GoGetHandler)))).Methods(http.MethodGet)
}
var gitRoutes = []GitRoute{
@@ -36,11 +36,7 @@ Redirecting to docs at <a href="https://godoc.org/{{ .ImportRoot }}/{{ .Repo }}"
`))
// GoGetHandler handles go get requests.
-type GoGetHandler struct{}
-
-var _ http.Handler = (*GoGetHandler)(nil)
-
-func (g GoGetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+func GoGetHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
cfg := config.FromContext(ctx)
be := backend.FromContext(ctx)
@@ -40,6 +40,11 @@ func (r *logWriter) WriteHeader(code int) {
r.ResponseWriter.WriteHeader(code)
}
+// Unwrap returns the underlying http.ResponseWriter.
+func (r *logWriter) Unwrap() http.ResponseWriter {
+ return r.ResponseWriter
+}
+
// Flush implements http.Flusher.
func (r *logWriter) Flush() {
if f, ok := r.ResponseWriter.(http.Flusher); ok {
@@ -8,7 +8,7 @@ import (
func renderStatus(code int) http.HandlerFunc {
return func(w http.ResponseWriter, _ *http.Request) {
- io.WriteString(w, fmt.Sprintf("%d %s", code, http.StatusText(code))) // nolint: errcheck
w.WriteHeader(code)
+ io.WriteString(w, fmt.Sprintf("%d %s", code, http.StatusText(code))) // nolint: errcheck
}
}