diff --git a/lib/godoc/godoc.html b/lib/godoc/godoc.html
index 671160d5a8..e99b758586 100644
--- a/lib/godoc/godoc.html
+++ b/lib/godoc/godoc.html
@@ -12,6 +12,9 @@
+{{if .SearchBox}}
+
+{{end}}
diff --git a/lib/godoc/opensearch.xml b/lib/godoc/opensearch.xml
new file mode 100644
index 0000000000..1b652db376
--- /dev/null
+++ b/lib/godoc/opensearch.xml
@@ -0,0 +1,11 @@
+
+
+ godoc
+ The Go Programming Language
+ go golang
+
+
+ /favicon.ico
+ UTF-8
+ UTF-8
+
diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go
index 35d5665b92..dfaadc4dfe 100644
--- a/src/cmd/godoc/godoc.go
+++ b/src/cmd/godoc/godoc.go
@@ -105,6 +105,7 @@ func registerPublicHandlers(mux *http.ServeMux) {
mux.HandleFunc("/doc/codewalk/", codewalk)
mux.HandleFunc("/search", search)
mux.Handle("/robots.txt", fileServer)
+ mux.HandleFunc("/opensearch.xml", serveSearchDesc)
mux.HandleFunc("/", serveFile)
}
@@ -600,7 +601,8 @@ var (
packageHTML,
packageText,
searchHTML,
- searchText *template.Template
+ searchText,
+ searchDescXML *template.Template
)
func readTemplates() {
@@ -615,6 +617,7 @@ func readTemplates() {
packageText = readTemplate("package.txt")
searchHTML = readTemplate("search.html")
searchText = readTemplate("search.txt")
+ searchDescXML = readTemplate("opensearch.xml")
}
// ----------------------------------------------------------------------------
@@ -809,6 +812,16 @@ func serveFile(w http.ResponseWriter, r *http.Request) {
fileServer.ServeHTTP(w, r)
}
+func serveSearchDesc(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/opensearchdescription+xml")
+ data := map[string]interface{}{
+ "BaseURL": fmt.Sprintf("http://%s", r.Host),
+ }
+ if err := searchDescXML.Execute(w, &data); err != nil {
+ log.Printf("searchDescXML.Execute: %s", err)
+ }
+}
+
// ----------------------------------------------------------------------------
// Packages