From ecf4a9216edfdcc48327382697fed5d98d7faf46 Mon Sep 17 00:00:00 2001 From: Christoph Hack Date: Mon, 12 Dec 2011 18:01:06 -0500 Subject: [PATCH] godoc: added an opensearch description document. R=golang-dev, r, tux21b, rsc CC=golang-dev https://golang.org/cl/5479062 --- lib/godoc/godoc.html | 3 +++ lib/godoc/opensearch.xml | 11 +++++++++++ src/cmd/godoc/godoc.go | 15 ++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 lib/godoc/opensearch.xml diff --git a/lib/godoc/godoc.html b/lib/godoc/godoc.html index 671160d5a81..e99b7585862 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 00000000000..1b652db3763 --- /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 35d5665b92e..dfaadc4dfe8 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