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
|
|
@ -80,6 +80,18 @@ func StaticFS() (fs.FS, error) {
|
|||
return fs.Sub(staticFS, "static")
|
||||
}
|
||||
|
||||
// OpenSearchXML returns the OpenSearch description XML with {baseUrl}
|
||||
// replaced by the provided base URL.
|
||||
func OpenSearchXML(baseURL string) ([]byte, error) {
|
||||
tmplFS, _ := fs.Sub(templatesFS, "templates")
|
||||
data, err := fs.ReadFile(tmplFS, "opensearch.xml")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := strings.ReplaceAll(string(data), "{baseUrl}", baseURL)
|
||||
return []byte(result), nil
|
||||
}
|
||||
|
||||
// FromResponse builds PageData from a search response and request params.
|
||||
func FromResponse(resp contracts.SearchResponse, query string, pageno int) PageData {
|
||||
pd := PageData{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue