all repos — nirvash @ 358d4fb2af62189b913432997462a71b61090eb4

modular CMS using the quartzgun library

lfo/middleware.go (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package lfo

import (
	"context"
	"net/http"
	core "nilfm.cc/git/nirvash/archetype"
)

func WithAdapter(next http.Handler, adapter core.Adapter) http.Handler {
	handlerFunc := func(w http.ResponseWriter, req *http.Request) {
		*req = *req.WithContext(context.WithValue(req.Context(), "adapter", adapter))
		next.ServeHTTP(w, req)
	}

	return http.HandlerFunc(handlerFunc)
}

func WithEditModes(next http.Handler) http.Handler {
	handlerFunc := func(w http.ResponseWriter, req *http.Request) {
		*req = *req.WithContext(context.WithValue(req.Context(), "edit-modes", map[string]core.EditMode{
			"Literal": core.EditModeLiteralTextArea,
			"Escaped": core.EditModeEscapedContentEditable,
		}))
		next.ServeHTTP(w, req)
	}

	return http.HandlerFunc(handlerFunc)
}