mirror of
https://github.com/golang/go
synced 2024-11-22 13:24:53 -07:00
parent
07b6becc88
commit
79284cae32
@ -86,7 +86,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
var fsTree RWValue; // *Directory tree of packages, updated with each sync
|
var fsTree RWValue // *Directory tree of packages, updated with each sync
|
||||||
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -139,9 +139,9 @@ func htmlEscape(s string) string {
|
|||||||
// Package directories
|
// Package directories
|
||||||
|
|
||||||
type Directory struct {
|
type Directory struct {
|
||||||
Path string; // includes Name
|
Path string; // includes Name
|
||||||
Name string;
|
Name string;
|
||||||
Dirs []*Directory;
|
Dirs []*Directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ func newDirTree(path, name string, depth int) *Directory {
|
|||||||
return &Directory{path, name, nil};
|
return &Directory{path, name, nil};
|
||||||
}
|
}
|
||||||
|
|
||||||
list, _ := io.ReadDir(path); // ignore errors
|
list, _ := io.ReadDir(path); // ignore errors
|
||||||
|
|
||||||
// determine number of subdirectories and package files
|
// determine number of subdirectories and package files
|
||||||
ndirs := 0;
|
ndirs := 0;
|
||||||
@ -210,7 +210,7 @@ func newDirectory(root string, depth int) *Directory {
|
|||||||
|
|
||||||
// lookup looks for the *Directory for a given path, relative to dir.
|
// lookup looks for the *Directory for a given path, relative to dir.
|
||||||
func (dir *Directory) lookup(path string) *Directory {
|
func (dir *Directory) lookup(path string) *Directory {
|
||||||
path = pathutil.Clean(path); // no trailing '/'
|
path = pathutil.Clean(path); // no trailing '/'
|
||||||
|
|
||||||
if dir == nil || path == "" || path == "." {
|
if dir == nil || path == "" || path == "." {
|
||||||
return dir;
|
return dir;
|
||||||
@ -224,7 +224,7 @@ func (dir *Directory) lookup(path string) *Directory {
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dir.lookup(dpath).lookup(dname);
|
return dir.lookup(dpath).lookup(dname);
|
||||||
@ -404,7 +404,7 @@ func htmlFmt(w io.Writer, x interface{}, format string) {
|
|||||||
func htmlCommentFmt(w io.Writer, x interface{}, format string) {
|
func htmlCommentFmt(w io.Writer, x interface{}, format string) {
|
||||||
var buf bytes.Buffer;
|
var buf bytes.Buffer;
|
||||||
writeAny(&buf, x, false);
|
writeAny(&buf, x, false);
|
||||||
doc.ToHtml(w, buf.Bytes()); // does html-escaping
|
doc.ToHtml(w, buf.Bytes()); // does html-escaping
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -416,7 +416,7 @@ func textFmt(w io.Writer, x interface{}, format string) {
|
|||||||
|
|
||||||
// Template formatter for "dir" format.
|
// Template formatter for "dir" format.
|
||||||
func dirFmt(w io.Writer, x interface{}, format string) {
|
func dirFmt(w io.Writer, x interface{}, format string) {
|
||||||
_ = x.(*Directory); // die quickly if x has the wrong type
|
_ = x.(*Directory); // die quickly if x has the wrong type
|
||||||
if err := dirsHtml.Execute(x, w); err != nil {
|
if err := dirsHtml.Execute(x, w); err != nil {
|
||||||
log.Stderrf("dirsHtml.Execute: %s", err);
|
log.Stderrf("dirsHtml.Execute: %s", err);
|
||||||
}
|
}
|
||||||
@ -425,7 +425,7 @@ func dirFmt(w io.Writer, x interface{}, format string) {
|
|||||||
|
|
||||||
func removePrefix(s, prefix string) string {
|
func removePrefix(s, prefix string) string {
|
||||||
if strings.HasPrefix(s, prefix) {
|
if strings.HasPrefix(s, prefix) {
|
||||||
return s[len(prefix) : len(s)];
|
return s[len(prefix):len(s)];
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -471,7 +471,7 @@ var infoClasses = [nKinds]string{
|
|||||||
|
|
||||||
// Template formatter for "infoClass" format.
|
// Template formatter for "infoClass" format.
|
||||||
func infoClassFmt(w io.Writer, x interface{}, format string) {
|
func infoClassFmt(w io.Writer, x interface{}, format string) {
|
||||||
fmt.Fprintf(w, infoClasses[x.(SpotInfo).Kind()]); // no html escaping needed
|
fmt.Fprintf(w, infoClasses[x.(SpotInfo).Kind()]); // no html escaping needed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -530,12 +530,12 @@ func readTemplate(name string) *template.Template {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
dirsHtml,
|
dirsHtml,
|
||||||
godocHtml,
|
godocHtml,
|
||||||
packageHtml,
|
packageHtml,
|
||||||
packageText,
|
packageText,
|
||||||
parseerrorHtml,
|
parseerrorHtml,
|
||||||
parseerrorText,
|
parseerrorText,
|
||||||
searchHtml *template.Template;
|
searchHtml *template.Template;
|
||||||
)
|
)
|
||||||
|
|
||||||
func readTemplates() {
|
func readTemplates() {
|
||||||
@ -694,9 +694,9 @@ type PageInfo struct {
|
|||||||
|
|
||||||
|
|
||||||
type httpHandler struct {
|
type httpHandler struct {
|
||||||
pattern string; // url pattern; e.g. "/pkg/"
|
pattern string; // url pattern; e.g. "/pkg/"
|
||||||
fsRoot string; // file system root to which the pattern is mapped
|
fsRoot string; // file system root to which the pattern is mapped
|
||||||
isPkg bool; // true if this handler serves real package documentation (as opposed to command documentation)
|
isPkg bool; // true if this handler serves real package documentation (as opposed to command documentation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -754,14 +754,14 @@ func (h *httpHandler) getPageInfo(path string) PageInfo {
|
|||||||
// or command-line mode); compute one level for this page
|
// or command-line mode); compute one level for this page
|
||||||
dir = newDirectory(dirname, 1);
|
dir = newDirectory(dirname, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PageInfo{pdoc, dir, h.isPkg};
|
return PageInfo{pdoc, dir, h.isPkg};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (h *httpHandler) ServeHTTP(c *http.Conn, r *http.Request) {
|
func (h *httpHandler) ServeHTTP(c *http.Conn, r *http.Request) {
|
||||||
path := r.Url.Path;
|
path := r.Url.Path;
|
||||||
path = path[len(h.pattern) : len(path)];
|
path = path[len(h.pattern):len(path)];
|
||||||
|
|
||||||
// canonicalize URL path and redirect if necessary
|
// canonicalize URL path and redirect if necessary
|
||||||
if canonical := pathutil.Clean(h.pattern + path) + "/"; r.Url.Path != canonical {
|
if canonical := pathutil.Clean(h.pattern + path) + "/"; r.Url.Path != canonical {
|
||||||
@ -797,7 +797,7 @@ func (h *httpHandler) ServeHTTP(c *http.Conn, r *http.Request) {
|
|||||||
_, pkgname := pathutil.Split(pathutil.Clean(path));
|
_, pkgname := pathutil.Split(pathutil.Clean(path));
|
||||||
title = "Command " + pkgname;
|
title = "Command " + pkgname;
|
||||||
default:
|
default:
|
||||||
title = "Command " + info.PDoc.PackageName
|
title = "Command " + info.PDoc.PackageName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -850,8 +850,8 @@ func search(c *http.Conn, r *http.Request) {
|
|||||||
// Server
|
// Server
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cmdHandler = httpHandler{"/cmd/", *cmdroot, false};
|
cmdHandler = httpHandler{"/cmd/", *cmdroot, false};
|
||||||
pkgHandler = httpHandler{"/pkg/", *pkgroot, true};
|
pkgHandler = httpHandler{"/pkg/", *pkgroot, true};
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -885,4 +885,3 @@ func indexer() {
|
|||||||
time.Sleep(1*60e9); // try once a minute
|
time.Sleep(1*60e9); // try once a minute
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ var (
|
|||||||
httpaddr = flag.String("http", "", "HTTP service address (e.g., ':6060')");
|
httpaddr = flag.String("http", "", "HTTP service address (e.g., ':6060')");
|
||||||
|
|
||||||
// layout control
|
// layout control
|
||||||
html = flag.Bool("html", false, "print HTML in command-line mode");
|
html = flag.Bool("html", false, "print HTML in command-line mode");
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ func exec(c *http.Conn, args []string) (status int) {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
status = wait.ExitStatus();
|
status = wait.ExitStatus();
|
||||||
if !wait.Exited() || status > 1 {
|
if !wait.Exited() || status > 1 {
|
||||||
os.Stderr.Write(buf.Bytes());
|
os.Stderr.Write(buf.Bytes());
|
||||||
log.Stderrf("executing %v failed (exit status = %d)", args, status);
|
log.Stderrf("executing %v failed (exit status = %d)", args, status);
|
||||||
return;
|
return;
|
||||||
@ -98,7 +98,7 @@ func exec(c *http.Conn, args []string) (status int) {
|
|||||||
|
|
||||||
|
|
||||||
// Maximum directory depth, adjust as needed.
|
// Maximum directory depth, adjust as needed.
|
||||||
const maxDirDepth = 24;
|
const maxDirDepth = 24
|
||||||
|
|
||||||
func dosync(c *http.Conn, r *http.Request) {
|
func dosync(c *http.Conn, r *http.Request) {
|
||||||
args := []string{"/bin/sh", "-c", *syncCmd};
|
args := []string{"/bin/sh", "-c", *syncCmd};
|
||||||
@ -125,7 +125,7 @@ func dosync(c *http.Conn, r *http.Request) {
|
|||||||
func usage() {
|
func usage() {
|
||||||
fmt.Fprintf(os.Stderr,
|
fmt.Fprintf(os.Stderr,
|
||||||
"usage: godoc package [name ...]\n"
|
"usage: godoc package [name ...]\n"
|
||||||
" godoc -http=:6060\n");
|
" godoc -http=:6060\n");
|
||||||
flag.PrintDefaults();
|
flag.PrintDefaults();
|
||||||
os.Exit(2);
|
os.Exit(2);
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,8 @@ func (p *ebnfParser) parseTerm() bool {
|
|||||||
|
|
||||||
|
|
||||||
func (p *ebnfParser) parseSequence() {
|
func (p *ebnfParser) parseSequence() {
|
||||||
for p.parseTerm() {}
|
for p.parseTerm() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ Yacc adepts will have no trouble adapting to this form of the tool.
|
|||||||
|
|
||||||
The file units.y in this directory is a yacc grammar for a version of
|
The file units.y in this directory is a yacc grammar for a version of
|
||||||
the Unix tool units, also written in Go and largely transliterated
|
the Unix tool units, also written in Go and largely transliterated
|
||||||
from the Plan 9 C version.
|
from the Plan 9 C version.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package documentation
|
package documentation
|
||||||
|
Loading…
Reference in New Issue
Block a user