mirror of
https://github.com/golang/go
synced 2024-11-25 17:07:57 -07:00
godoc: fix remote search (use correct URL)
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
This commit is contained in:
parent
3f2d787c2b
commit
e8188c1607
@ -16,6 +16,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -845,6 +846,19 @@ func getPageInfoMode(r *http.Request) (mode PageInfoMode) {
|
|||||||
return
|
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 {
|
type PageInfo struct {
|
||||||
Dirname string // directory containing the package
|
Dirname string // directory containing the package
|
||||||
PList []string // list of package names found
|
PList []string // list of package names found
|
||||||
|
@ -38,7 +38,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof" // to serve /debug/pprof/*
|
_ "net/http/pprof" // to serve /debug/pprof/*
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -165,8 +164,6 @@ func loggingHandler(h http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func remoteSearch(query string) (res *http.Response, err error) {
|
func remoteSearch(query string) (res *http.Response, err error) {
|
||||||
search := "/search?f=text&q=" + url.QueryEscape(query)
|
|
||||||
|
|
||||||
// list of addresses to try
|
// list of addresses to try
|
||||||
var addrs []string
|
var addrs []string
|
||||||
if *serverAddr != "" {
|
if *serverAddr != "" {
|
||||||
@ -180,6 +177,7 @@ func remoteSearch(query string) (res *http.Response, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remote search
|
// remote search
|
||||||
|
search := remoteSearchURL(query, *html)
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
url := "http://" + addr + search
|
url := "http://" + addr + search
|
||||||
res, err = http.Get(url)
|
res, err = http.Get(url)
|
||||||
|
Loading…
Reference in New Issue
Block a user