diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -88,6 +88,12 @@ pkgHandler httpHandler ) +// OPENSUSE-PATCHFIX-GODOC-LOCATIONS +const ( + docroot = "/usr/share/doc/packages/go-doc/doc" + srcroot = "/usr/share/go/" +) + func initHandlers() { paths := filepath.SplitList(*pkgPath) for _, t := range build.Path { @@ -98,9 +104,9 @@ } fsMap.Init(paths) - fileServer = http.FileServer(fsHttp) - cmdHandler = httpHandler{"/cmd/", filepath.Join(*goroot, "src", "cmd"), false} - pkgHandler = httpHandler{"/pkg/", filepath.Join(*goroot, "src", "pkg"), true} + fileServer = http.FileServer(http.Dir(docroot)) + cmdHandler = httpHandler{"/cmd/", filepath.Join(srcroot, "src/cmd"), false} + pkgHandler = httpHandler{"/pkg/", filepath.Join(srcroot, "src/pkg"), true} } func registerPublicHandlers(mux *http.ServeMux) { @@ -603,7 +609,7 @@ } func readTemplate(name string) *template.Template { - path := filepath.Join(*goroot, "lib", "godoc", name) + path := filepath.Join(*goroot, "lib/"+name) if *templateDir != "" { defaultpath := path path = filepath.Join(*templateDir, name) @@ -780,6 +786,16 @@ } func serveFile(w http.ResponseWriter, r *http.Request) { + // openSUSE: serv docs from root of go-doc package install location + if strings.HasPrefix(r.URL.Path, "/doc/") { + http.Redirect(w, r, "/"+ r.URL.Path[len("/doc"):], http.StatusMovedPermanently) + return + } + if r.URL.Path == "/" { + serveHTMLDoc(w, r, filepath.Join(docroot, "root.html"), "root.html") + return + } + relpath := r.URL.Path // Check to see if we need to redirect or serve another file. @@ -794,7 +810,7 @@ } relpath = relpath[1:] // strip leading slash - abspath := absolutePath(relpath, *goroot) + abspath := absolutePath(relpath, docroot) switch path.Ext(relpath) { case ".html": @@ -1368,7 +1384,7 @@ metadata[meta.filePath] = &meta } } - scan(filepath.Join(*goroot, "doc")) + scan(filepath.Join(docroot, "")) docMetadata.set(metadata) }