LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // godoc: Go Documentation Server | 5 // godoc: Go Documentation Server |
6 | 6 |
7 // Web server tree: | 7 // Web server tree: |
8 // | 8 // |
9 // http://godoc/ main landing page | 9 // http://godoc/ main landing page |
10 // http://godoc/doc/ serve from $GOROOT/doc - spec, mem, tutorial, et
c. | 10 // http://godoc/doc/ serve from $GOROOT/doc - spec, mem, tutorial, et
c. |
(...skipping 18 matching lines...) Expand all Loading... |
29 "bytes" | 29 "bytes" |
30 _ "expvar" // to serve /debug/vars | 30 _ "expvar" // to serve /debug/vars |
31 "flag" | 31 "flag" |
32 "fmt" | 32 "fmt" |
33 "go/ast" | 33 "go/ast" |
34 "http" | 34 "http" |
35 _ "http/pprof" // to serve /debug/pprof/* | 35 _ "http/pprof" // to serve /debug/pprof/* |
36 "io" | 36 "io" |
37 "log" | 37 "log" |
38 "os" | 38 "os" |
39 » pathutil "path" | 39 » "path/filepath" |
40 "regexp" | 40 "regexp" |
41 "runtime" | 41 "runtime" |
42 "strings" | 42 "strings" |
43 "time" | 43 "time" |
44 ) | 44 ) |
45 | 45 |
46 const defaultAddr = ":6060" // default webserver address | 46 const defaultAddr = ":6060" // default webserver address |
47 | 47 |
48 var ( | 48 var ( |
49 // periodic sync | 49 // periodic sync |
(...skipping 26 matching lines...) Expand all Loading... |
76 if err != nil { | 76 if err != nil { |
77 log.Printf("os.Pipe(): %v", err) | 77 log.Printf("os.Pipe(): %v", err) |
78 return 2 | 78 return 2 |
79 } | 79 } |
80 | 80 |
81 bin := args[0] | 81 bin := args[0] |
82 fds := []*os.File{nil, w, w} | 82 fds := []*os.File{nil, w, w} |
83 if *verbose { | 83 if *verbose { |
84 log.Printf("executing %v", args) | 84 log.Printf("executing %v", args) |
85 } | 85 } |
86 » var attrs os.ProcAttributes | 86 » p, err := os.StartProcess(bin, args, &os.ProcAttr{Files: fds, Dir: *goro
ot}) |
87 » attrs.Chdir(*goroot) | |
88 » p, err := os.StartProcess(bin, args, os.Environ(), fds, &attrs) | |
89 defer r.Close() | 87 defer r.Close() |
90 w.Close() | 88 w.Close() |
91 if err != nil { | 89 if err != nil { |
92 log.Printf("os.StartProcess(%q): %v", bin, err) | 90 log.Printf("os.StartProcess(%q): %v", bin, err) |
93 return 2 | 91 return 2 |
94 } | 92 } |
95 defer p.Release() | 93 defer p.Release() |
96 | 94 |
97 var buf bytes.Buffer | 95 var buf bytes.Buffer |
98 io.Copy(&buf, r) | 96 io.Copy(&buf, r) |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 io.Copy(os.Stdout, res.Body) | 307 io.Copy(os.Stdout, res.Body) |
310 } | 308 } |
311 return | 309 return |
312 } | 310 } |
313 | 311 |
314 // determine paths | 312 // determine paths |
315 path := flag.Arg(0) | 313 path := flag.Arg(0) |
316 if len(path) > 0 && path[0] == '.' { | 314 if len(path) > 0 && path[0] == '.' { |
317 // assume cwd; don't assume -goroot | 315 // assume cwd; don't assume -goroot |
318 cwd, _ := os.Getwd() // ignore errors | 316 cwd, _ := os.Getwd() // ignore errors |
319 » » path = pathutil.Join(cwd, path) | 317 » » path = filepath.Join(cwd, path) |
320 } | 318 } |
321 relpath := path | 319 relpath := path |
322 abspath := path | 320 abspath := path |
323 » if !pathutil.IsAbs(path) { | 321 » if !filepath.IsAbs(path) { |
324 abspath = absolutePath(path, pkgHandler.fsRoot) | 322 abspath = absolutePath(path, pkgHandler.fsRoot) |
325 } else { | 323 } else { |
326 » » relpath = relativePath(path) | 324 » » relpath = relativeURL(path) |
327 } | 325 } |
328 | 326 |
329 var mode PageInfoMode | 327 var mode PageInfoMode |
330 if *srcMode { | 328 if *srcMode { |
331 // only filter exports if we don't have explicit command-line fi
lter arguments | 329 // only filter exports if we don't have explicit command-line fi
lter arguments |
332 if flag.NArg() == 1 { | 330 if flag.NArg() == 1 { |
333 mode |= exportsOnly | 331 mode |= exportsOnly |
334 } | 332 } |
335 } else { | 333 } else { |
336 mode = exportsOnly | genDoc | 334 mode = exportsOnly | genDoc |
337 } | 335 } |
338 // TODO(gri): Provide a mechanism (flag?) to select a package | 336 // TODO(gri): Provide a mechanism (flag?) to select a package |
339 // if there are multiple packages in a directory. | 337 // if there are multiple packages in a directory. |
340 info := pkgHandler.getPageInfo(abspath, relpath, "", mode) | 338 info := pkgHandler.getPageInfo(abspath, relpath, "", mode) |
341 | 339 |
342 if info.IsEmpty() { | 340 if info.IsEmpty() { |
343 // try again, this time assume it's a command | 341 // try again, this time assume it's a command |
344 » » if !pathutil.IsAbs(path) { | 342 » » if !filepath.IsAbs(path) { |
345 abspath = absolutePath(path, cmdHandler.fsRoot) | 343 abspath = absolutePath(path, cmdHandler.fsRoot) |
346 } | 344 } |
347 cmdInfo := cmdHandler.getPageInfo(abspath, relpath, "", mode) | 345 cmdInfo := cmdHandler.getPageInfo(abspath, relpath, "", mode) |
348 // only use the cmdInfo if it actually contains a result | 346 // only use the cmdInfo if it actually contains a result |
349 // (don't hide errors reported from looking up a package) | 347 // (don't hide errors reported from looking up a package) |
350 if !cmdInfo.IsEmpty() { | 348 if !cmdInfo.IsEmpty() { |
351 info = cmdInfo | 349 info = cmdInfo |
352 } | 350 } |
353 } | 351 } |
354 if info.Err != nil { | 352 if info.Err != nil { |
(...skipping 30 matching lines...) Expand all Loading... |
385 | 383 |
386 case info.PDoc != nil: | 384 case info.PDoc != nil: |
387 info.PDoc.Filter(filter) | 385 info.PDoc.Filter(filter) |
388 } | 386 } |
389 } | 387 } |
390 | 388 |
391 if err := packageText.Execute(os.Stdout, info); err != nil { | 389 if err := packageText.Execute(os.Stdout, info); err != nil { |
392 log.Printf("packageText.Execute: %s", err) | 390 log.Printf("packageText.Execute: %s", err) |
393 } | 391 } |
394 } | 392 } |
LEFT | RIGHT |