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
43 lines
783 B
Go
43 lines
783 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/ashie/gosearch/internal/httpapi"
|
|
"github.com/ashie/gosearch/internal/search"
|
|
)
|
|
|
|
func main() {
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
}
|
|
|
|
upstreamURL := os.Getenv("UPSTREAM_SEARXNG_URL")
|
|
|
|
timeout := 10 * time.Second
|
|
if v := os.Getenv("HTTP_TIMEOUT"); v != "" {
|
|
if d, err := time.ParseDuration(v); err == nil {
|
|
timeout = d
|
|
}
|
|
}
|
|
|
|
svc := search.NewService(search.ServiceConfig{
|
|
UpstreamURL: upstreamURL,
|
|
HTTPTimeout: timeout,
|
|
})
|
|
|
|
h := httpapi.NewHandler(svc)
|
|
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/healthz", h.Healthz)
|
|
mux.HandleFunc("/search", h.Search)
|
|
|
|
addr := ":" + port
|
|
log.Printf("searxng-go listening on %s", addr)
|
|
log.Fatal(http.ListenAndServe(addr, mux))
|
|
}
|
|
|