blob: 3991c6af2ad1c20917e06de8cba4236bae47bdab (
plain)
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
|
package test
import (
"net/http"
"sync"
)
// HandlerSet is a struct with a mutex that allows us to swap handlers while a test server is running
type HandlerSet struct {
mu sync.Mutex
handler http.Handler
}
func (hs *HandlerSet) SetHandler(handler http.Handler) {
hs.mu.Lock()
hs.handler = handler
hs.mu.Unlock()
}
func (hs *HandlerSet) ServeHTTP(w http.ResponseWriter, r *http.Request) {
hs.mu.Lock()
handler := hs.handler
hs.mu.Unlock()
handler.ServeHTTP(w, r)
}
|