feat: establish Orbit models, migrations and development baseline
This commit is contained in:
34
internal/transport/httpserver/server.go
Normal file
34
internal/transport/httpserver/server.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Package httpserver exposes bootstrap health endpoints only. Task, workflow,
|
||||
// authentication and WebSocket APIs will be implemented in subsequent slices.
|
||||
package httpserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Checker func(context.Context) error
|
||||
|
||||
func New(addr string, ready Checker) *http.Server {
|
||||
mux := http.NewServeMux()
|
||||
write := func(w http.ResponseWriter, status int, body map[string]string) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
_ = json.NewEncoder(w).Encode(body)
|
||||
}
|
||||
mux.HandleFunc("GET /health/live", func(w http.ResponseWriter, r *http.Request) {
|
||||
write(w, http.StatusOK, map[string]string{"status": "alive"})
|
||||
})
|
||||
mux.HandleFunc("GET /health/ready", func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second)
|
||||
defer cancel()
|
||||
if ready == nil || ready(ctx) != nil {
|
||||
write(w, http.StatusServiceUnavailable, map[string]string{"status": "not_ready"})
|
||||
return
|
||||
}
|
||||
write(w, http.StatusOK, map[string]string{"status": "ready", "scope": "database_and_schema"})
|
||||
})
|
||||
return &http.Server{Addr: addr, Handler: mux, ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, IdleTimeout: 60 * time.Second, MaxHeaderBytes: 16 << 10}
|
||||
}
|
||||
Reference in New Issue
Block a user