Files
plainleaf/server/spaces.go
T
Zef HemelandGitHub a524c64884 Go backend (#1555)
* Replaces old Deno server with a Go implementation
* Restructured the code base accordingly
2025-09-19 13:23:20 +02:00

23 lines
597 B
Go

package server
import (
"context"
"net/http"
)
const spaceConfigKey = "spaceConfig"
func spaceMiddleware(config *ServerConfig) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
spaceConfig := config.SpaceConfigResolver(r)
augmentedRequest := r.WithContext(context.WithValue(r.Context(), spaceConfigKey, spaceConfig))
next.ServeHTTP(w, augmentedRequest)
})
}
}
func spaceConfigFromContext(ctx context.Context) *SpaceConfig {
return ctx.Value(spaceConfigKey).(*SpaceConfig)
}