all repos — nirvash @ 3f04afa16e7e6d2f76e114e1b5591f82ea904134

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
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)
}