aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/middleware.go
blob: 0dcf5580c5ee9000b6e784f58c33f19d47152c71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package admin

import (
	"fmt"
	"net/http"
)

// Hooks middleware to handle requests to the admin repo.
func Hooks(adminSvc *Servicer, next http.Handler) http.Handler {
	repoUpdatePath := fmt.Sprintf("/%s/git-receive-pack", mgmtRepoName)
	return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
		next.ServeHTTP(rw, req)
		if req.URL.Path == repoUpdatePath && req.Method == http.MethodPost {
			adminSvc.Reload()
		}
	})
}