feat: add OpenSearch XML endpoint
- Serve /opensearch.xml with configurable base URL - Browsers can now add gosearch as a search engine from the address bar - Configurable via [server] base_url or BASE_URL env var - XML template embedded in the binary via go:embed - Added base_url to config.example.toml
This commit is contained in:
parent
3caf702c4f
commit
4ec600f6c0
6 changed files with 51 additions and 0 deletions
|
|
@ -33,6 +33,19 @@ func (h *Handler) Index(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// OpenSearch serves the OpenSearch description XML.
|
||||
func (h *Handler) OpenSearch(baseURL string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
xml, err := views.OpenSearchXML(baseURL)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/opensearchdescription+xml; charset=utf-8")
|
||||
w.Write(xml)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) Search(w http.ResponseWriter, r *http.Request) {
|
||||
// For HTML format with no query, redirect to homepage.
|
||||
if r.FormValue("q") == "" && (r.FormValue("format") == "" || r.FormValue("format") == "html") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue