Added code for backend glue

This commit is contained in:
2025-10-13 19:20:24 -04:00
parent 692b069b5b
commit 29a451ab58
25 changed files with 1063 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package http
import (
"encoding/json"
"net/http"
"mind/internal/config"
"mind/internal/glue"
"mind/internal/logx"
)
type server struct {
log *logx.Logger
cfg config.Config
glue *glue.Glue
}
func NewRouter(l *logx.Logger, c config.Config, g *glue.Glue) http.Handler {
s := &server{log: l, cfg: c, glue: g}
mux := http.NewServeMux()
mux.HandleFunc("/healthz", s.health)
mux.HandleFunc("/conversations", s.conversations)
mux.HandleFunc("/branches", s.branches)
mux.HandleFunc("/completion", s.completion)
mux.HandleFunc("/linearize", s.linearize)
return withCommon(mux)
}
func (s *server) health(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
_, _ = w.Write([]byte("ok"))
}
// Helpers
func writeJSON(w http.ResponseWriter, code int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
_ = json.NewEncoder(w).Encode(v)
}