36 lines
805 B
Go
36 lines
805 B
Go
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,
|
|
)),
|
|
)
|
|
}
|
|
}
|