Files
tutor-service/internal/httpapi/handler.go
2026-04-26 16:14:31 +09:00

48 lines
965 B
Go

package httpapi
import (
"encoding/json"
"net/http"
"tutor/internal/config"
"tutor/internal/workflows"
)
type Handler struct {
cfg config.Config
runner workflows.Runner
}
func NewHandler(cfg config.Config, runner workflows.Runner) Handler {
return Handler{
cfg: cfg,
runner: runner,
}
}
func (h Handler) Routes() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("GET /healthz", h.health)
return mux
}
func (h Handler) health(w http.ResponseWriter, _ *http.Request) {
writeJSON(w, http.StatusOK, healthResponse{
Status: "ok",
Environment: h.cfg.Environment,
ModelKey: h.cfg.ModelKey,
})
}
type healthResponse struct {
Status string `json:"status"`
Environment string `json:"environment"`
ModelKey string `json:"model_key"`
}
func writeJSON(w http.ResponseWriter, status int, value any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(value)
}