...
1 package middleware
2
3 import (
4 "net/http"
5 "strings"
6 )
7
8
9
10
11
12 func Heartbeat(endpoint string) func(http.Handler) http.Handler {
13 f := func(h http.Handler) http.Handler {
14 fn := func(w http.ResponseWriter, r *http.Request) {
15 if r.Method == "GET" && strings.EqualFold(r.URL.Path, endpoint) {
16 w.Header().Set("Content-Type", "text/plain")
17 w.WriteHeader(http.StatusOK)
18 w.Write([]byte("."))
19 return
20 }
21 h.ServeHTTP(w, r)
22 }
23 return http.HandlerFunc(fn)
24 }
25 return f
26 }
27
View as plain text