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, etc. | 10 // http://godoc/doc/ serve from $GOROOT/doc - spec, mem, etc. |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 for i := 0; i < flag.NArg(); i++ { | 361 for i := 0; i < flag.NArg(); i++ { |
362 res, err := remoteSearch(flag.Arg(i)) | 362 res, err := remoteSearch(flag.Arg(i)) |
363 if err != nil { | 363 if err != nil { |
364 log.Fatalf("remoteSearch: %s", err) | 364 log.Fatalf("remoteSearch: %s", err) |
365 } | 365 } |
366 io.Copy(os.Stdout, res.Body) | 366 io.Copy(os.Stdout, res.Body) |
367 } | 367 } |
368 return | 368 return |
369 } | 369 } |
370 | 370 |
371 » // Determine paths. | 371 » // determine paths |
372 » // | |
373 » // If we are passed an operating system path like . or ./foo or /foo/ba
r or c:\mysrc, | |
374 » // we need to map that path somewhere in the fs name space so that routi
nes | |
375 » // like getPageInfo will see it. We use the arbitrarily-chosen virtual
path "/target" | |
376 » // for this. That is, if we get passed a directory like the above, we m
ap that | |
377 » // directory so that getPageInfo sees it as /target. | |
378 » const target = "/target" | |
379 const cmdPrefix = "cmd/" | 372 const cmdPrefix = "cmd/" |
380 path := flag.Arg(0) | 373 path := flag.Arg(0) |
381 var forceCmd bool | 374 var forceCmd bool |
382 var abspath, relpath string | 375 var abspath, relpath string |
383 if filepath.IsAbs(path) { | 376 if filepath.IsAbs(path) { |
384 » » fs.Bind(target, OS(path), "/", bindReplace) | 377 » » fs.Bind("/target", OS(path), "/", bindReplace) |
385 » » abspath = target | 378 » » abspath = "/target" |
386 } else if build.IsLocalImport(path) { | 379 } else if build.IsLocalImport(path) { |
387 cwd, _ := os.Getwd() // ignore errors | 380 cwd, _ := os.Getwd() // ignore errors |
388 path = filepath.Join(cwd, path) | 381 path = filepath.Join(cwd, path) |
389 » » fs.Bind(target, OS(path), "/", bindReplace) | 382 » » fs.Bind("/target", OS(path), "/", bindReplace) |
390 » » abspath = target | 383 » » abspath = "/target" |
391 } else if strings.HasPrefix(path, cmdPrefix) { | 384 } else if strings.HasPrefix(path, cmdPrefix) { |
392 abspath = path[len(cmdPrefix):] | 385 abspath = path[len(cmdPrefix):] |
393 forceCmd = true | 386 forceCmd = true |
394 } else if bp, _ := build.Import(path, "", build.FindOnly); bp.Dir != ""
&& bp.ImportPath != "" { | 387 } else if bp, _ := build.Import(path, "", build.FindOnly); bp.Dir != ""
&& bp.ImportPath != "" { |
395 » » fs.Bind(target, OS(bp.Dir), "/", bindReplace) | 388 » » fs.Bind("/target", OS(bp.Dir), "/", bindReplace) |
396 » » abspath = target | 389 » » abspath = "/target" |
397 relpath = bp.ImportPath | 390 relpath = bp.ImportPath |
398 } else { | 391 } else { |
399 abspath = pathpkg.Join(pkgHandler.fsRoot, path) | 392 abspath = pathpkg.Join(pkgHandler.fsRoot, path) |
400 } | 393 } |
401 if relpath == "" { | 394 if relpath == "" { |
402 relpath = abspath | 395 relpath = abspath |
403 } | 396 } |
404 | 397 |
405 var mode PageInfoMode | 398 var mode PageInfoMode |
406 if relpath == builtinPkgPath { | 399 if relpath == builtinPkgPath { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 if info.PAst == nil && info.PDoc == nil { | 436 if info.PAst == nil && info.PDoc == nil { |
444 info = cinfo | 437 info = cinfo |
445 } else { | 438 } else { |
446 fmt.Printf("use 'godoc %s%s' for documentation on the %s
command \n\n", cmdPrefix, relpath, relpath) | 439 fmt.Printf("use 'godoc %s%s' for documentation on the %s
command \n\n", cmdPrefix, relpath, relpath) |
447 } | 440 } |
448 } | 441 } |
449 | 442 |
450 if info.Err != nil { | 443 if info.Err != nil { |
451 log.Fatalf("%v", info.Err) | 444 log.Fatalf("%v", info.Err) |
452 } | 445 } |
453 » if info.PDoc.ImportPath == target { | 446 » if info.PDoc.ImportPath == "/target" { |
454 » » // Replace virtual /target with actual argument from command lin
e. | |
455 info.PDoc.ImportPath = flag.Arg(0) | 447 info.PDoc.ImportPath = flag.Arg(0) |
456 } | 448 } |
457 | 449 |
458 // If we have more than one argument, use the remaining arguments for fi
ltering | 450 // If we have more than one argument, use the remaining arguments for fi
ltering |
459 if flag.NArg() > 1 { | 451 if flag.NArg() > 1 { |
460 args := flag.Args()[1:] | 452 args := flag.Args()[1:] |
461 rx := makeRx(args) | 453 rx := makeRx(args) |
462 if rx == nil { | 454 if rx == nil { |
463 log.Fatalf("illegal regular expression from %v", args) | 455 log.Fatalf("illegal regular expression from %v", args) |
464 } | 456 } |
(...skipping 22 matching lines...) Expand all Loading... |
487 | 479 |
488 case info.PDoc != nil: | 480 case info.PDoc != nil: |
489 info.PDoc.Filter(filter) | 481 info.PDoc.Filter(filter) |
490 } | 482 } |
491 } | 483 } |
492 | 484 |
493 if err := packageText.Execute(os.Stdout, info); err != nil { | 485 if err := packageText.Execute(os.Stdout, info); err != nil { |
494 log.Printf("packageText.Execute: %s", err) | 486 log.Printf("packageText.Execute: %s", err) |
495 } | 487 } |
496 } | 488 } |
LEFT | RIGHT |