kafka/internal/httpapi/handlers.go
Franz Kafka dc44837219 feat: build Go-based SearXNG-compatible search service
Implement an API-first Go rewrite with local engine adapters, upstream fallback, and Nix-based tooling so searches can run without matching the original UI while preserving response compatibility.

Made-with: Cursor
2026-03-20 20:34:08 +01:00

41 lines
909 B
Go

package httpapi
import (
"net/http"
"github.com/ashie/gosearch/internal/search"
)
type Handler struct {
searchSvc *search.Service
}
func NewHandler(searchSvc *search.Service) *Handler {
return &Handler{searchSvc: searchSvc}
}
func (h *Handler) Healthz(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("OK"))
}
func (h *Handler) Search(w http.ResponseWriter, r *http.Request) {
req, err := search.ParseSearchRequest(r)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
resp, err := h.searchSvc.Search(r.Context(), req)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := search.WriteSearchResponse(w, req.Format, resp); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}