]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: fix remote search (use correct URL)
authorRobert Griesemer <gri@golang.org>
Sat, 12 Nov 2011 00:59:47 +0000 (16:59 -0800)
committerRobert Griesemer <gri@golang.org>
Sat, 12 Nov 2011 00:59:47 +0000 (16:59 -0800)
Also works now together with -html, as in:
godoc -html -q Sin
for an html result.

Fixes #2435.

R=iant
CC=golang-dev
https://golang.org/cl/5375074

src/cmd/godoc/godoc.go
src/cmd/godoc/main.go

index 6ddae54bb24261cadab5c7e124987403d6eecab8..9cc0352504b49bd3ee43a63434436efb1e41856d 100644 (file)
@@ -16,6 +16,7 @@ import (
        "io"
        "log"
        "net/http"
+       "net/url"
        "os"
        "path"
        "path/filepath"
@@ -845,6 +846,19 @@ func getPageInfoMode(r *http.Request) (mode PageInfoMode) {
        return
 }
 
+// remoteSearchURL returns the search URL for a given query as needed by
+// remoteSearch. If html is set, an html result is requested; otherwise
+// the result is in textual form.
+// Adjust this function as necessary if modeNames or FormValue parameters
+// change.
+func remoteSearchURL(query string, html bool) string {
+       s := "/search?m=text&q="
+       if html {
+               s = "/search?q="
+       }
+       return s + url.QueryEscape(query)
+}
+
 type PageInfo struct {
        Dirname  string          // directory containing the package
        PList    []string        // list of package names found
index 584c805a1befbefac5724c04f033bb60f1d29b00..e1a175d72dffe4d28e77f68f39c25e104ae112de 100644 (file)
@@ -38,7 +38,6 @@ import (
        "log"
        "net/http"
        _ "net/http/pprof" // to serve /debug/pprof/*
-       "net/url"
        "os"
        "path"
        "path/filepath"
@@ -165,8 +164,6 @@ func loggingHandler(h http.Handler) http.Handler {
 }
 
 func remoteSearch(query string) (res *http.Response, err error) {
-       search := "/search?f=text&q=" + url.QueryEscape(query)
-
        // list of addresses to try
        var addrs []string
        if *serverAddr != "" {
@@ -180,6 +177,7 @@ func remoteSearch(query string) (res *http.Response, err error) {
        }
 
        // remote search
+       search := remoteSearchURL(query, *html)
        for _, addr := range addrs {
                url := "http://" + addr + search
                res, err = http.Get(url)