summaryrefslogtreecommitdiff
path: root/internal/handler/hearthbeat.go
blob: 014880e0b58d1214bbdd5fc69ca499c8cdc49f7f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package handler

import (
	"net/http"

	"go.neonxp.dev/djson/internal/tree"
)

func (h *handler) Hearthbeat(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/plain")
	switch h.core.State() {
	case tree.Ready:
		w.WriteHeader(http.StatusOK)
		_, _ = w.Write([]byte("."))
	case tree.Failed:
		w.WriteHeader(http.StatusInternalServerError)
		_, _ = w.Write([]byte("start failed"))
	case tree.Running:
		w.WriteHeader(http.StatusServiceUnavailable)
		_, _ = w.Write([]byte("starting..."))
	}
}