No description
- Add internal/views/ package with embedded templates and static files - Go html/template with SearXNG-compatible CSS class names - Dark mode via prefers-color-scheme, responsive layout, print styles - HTMX integration: - Debounced instant search (500ms) on the search input - Form submission targets #results via hx-post - Pagination buttons are HTMX-powered (swap results div only) - HX-Request header detection for fragment vs full page rendering - Template structure: - base.html: full page layout with HTMX script, favicon, CSS - index.html: homepage with centered search box - results.html: full results page (wraps base + results_inner) - results_inner.html: results fragment (HTMX partial + sidebar + pagination) - result_item.html: reusable result article partial - Smart format detection: browser requests (Accept: text/html) default to HTML, API clients default to JSON - Static files served at /static/ from embedded FS (CSS, favicon SVG) - Index route at GET / - Empty query on HTML format redirects to homepage - Custom CSS (gosearch.css): clean, minimal, privacy-respecting aesthetic with light/dark mode, responsive breakpoints, print stylesheet - Add views package tests |
||
|---|---|---|
| cmd/searxng-go | ||
| internal | ||
| .gitignore | ||
| config.example.toml | ||
| docker-compose.yml | ||
| Dockerfile | ||
| flake.lock | ||
| flake.nix | ||
| go.mod | ||
| go.sum | ||
| README.md | ||
gosearch (SearXNG rewrite in Go)
This repository contains a standalone Go HTTP service that implements a SearXNG-compatible
API-first /search endpoint and proxies unported engines to an upstream SearXNG instance.
Endpoints
GET /healthz->OKGET|POST /search- Required form/body parameter:
q - Optional:
format(json|csv|rss; default:json)
- Required form/body parameter:
Supported format=...
json: SearXNG-style JSON response (query,number_of_results,results,answers,corrections,infoboxes,suggestions,unresponsive_engines)csv: CSV with headertitle,url,content,host,engine,score,typerss: RSS 2.0 feed based on theopensearch_response_rss.xmltemplate fields
Request parameters
The server accepts SearXNG form parameters (both GET query string and POST form-encoded):
q(required): search queryformat(optional):json/csv/rsspageno(optional, default1): positive integersafesearch(optional, default0): integer0..2time_range(optional):day|week|month|year(or omitted/None)timeout_limit(optional): float, seconds (or omitted/None)language(optional, defaultauto):autoor a BCP-47-ish language codeengines(optional): comma-separated engine names (e.g.wikipedia,arxiv)categories/category_<name>(optional): used for selecting the initial ported subsetengine_data-<engine>-<key>=<value>(optional): per-engine custom parameters
Environment variables
PORT(optional, default8080)UPSTREAM_SEARXNG_URL(optional for now, but required if you expect unported engines)- When set, unported engines are proxied to
${UPSTREAM_SEARXNG_URL}/searchwithformat=json.
- When set, unported engines are proxied to
LOCAL_PORTED_ENGINES(optional, defaultwikipedia,arxiv,crossref,braveapi,qwant)- Controls which engine names are executed locally (Go-native adapters).
HTTP_TIMEOUT(optional, default10s)- Timeout for both local engine API calls and upstream proxy calls.
- Brave Search API:
BRAVE_API_KEY(optional): enables thebraveapiengine when setBRAVE_ACCESS_TOKEN(optional): if set, requests must include a token (headerAuthorization: Bearer <token>,X-Search-Token,X-Brave-Access-Token, or form fieldtoken)
Ported vs proxied strategy
- The service plans which engines should run locally vs upstream using
LOCAL_PORTED_ENGINES. - It executes local ported engines using Go-native adapters:
wikipedia,arxiv,crossref
- Any remaining requested engines are proxied to upstream SearXNG (
format=json). - Responses are merged:
resultsare de-duplicated byengine|title|urlsuggestions/correctionsare treated as sets- other arrays are concatenated
Running with Nix
This repo uses flake.nix to provide the Go toolchain.
nix develop
go test ./...
go run ./cmd/searxng-go
Example:
export UPSTREAM_SEARXNG_URL="http://127.0.0.1:8888"
export PORT="8080"
nix develop -c go run ./cmd/searxng-go