server.go

 1package web
 2
 3import (
 4	"context"
 5	"net/http"
 6
 7	log "github.com/charmbracelet/log/v2"
 8	"github.com/gorilla/handlers"
 9	"github.com/gorilla/mux"
10)
11
12// NewRouter returns a new HTTP router.
13func NewRouter(ctx context.Context) http.Handler {
14	logger := log.FromContext(ctx).WithPrefix("http")
15	router := mux.NewRouter()
16
17	// Git routes
18	GitController(ctx, router)
19
20	router.PathPrefix("/").HandlerFunc(renderNotFound)
21
22	// Context handler
23	// Adds context to the request
24	h := NewLoggingMiddleware(router, logger)
25	h = NewContextHandler(ctx)(h)
26	h = handlers.CompressHandler(h)
27	h = handlers.RecoveryHandler()(h)
28
29	return h
30}