Add opensearch endpoint and handler
This commit is contained in:
35
internal/opensearch_handler.go
Normal file
35
internal/opensearch_handler.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
const OpenSearchTemplate string = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
||||
<ShortName>%s</ShortName>
|
||||
<Description>%s</Description>
|
||||
<Tags>search</Tags>
|
||||
<Contact>%s</Contact>
|
||||
<Url type="text/html" method="get" template="%s?q={searchTerms}"/>
|
||||
</OpenSearchDescription>
|
||||
`
|
||||
|
||||
// OpenSearchHandler ...
|
||||
func (s *Server) OpenSearchHandler() httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.Header().Set("Content-Type", "text/xml")
|
||||
|
||||
w.Write(
|
||||
[]byte(fmt.Sprintf(
|
||||
OpenSearchTemplate,
|
||||
s.config.Name,
|
||||
s.config.Description,
|
||||
s.config.AdminEmail,
|
||||
s.config.BaseURL,
|
||||
)),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user