Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(212)

Delta Between Two Patch Sets: src/cmd/godoc/godoc.go

Issue 7132044: code review 7132044: cmd/godoc: handle file name arguments better
Left Patch Set: diff -r e379fdfeb87e https://code.google.com/p/go Created 11 years, 2 months ago
Right Patch Set: diff -r dff6e212f5cb https://code.google.com/p/go Created 11 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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 package main 5 package main
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "encoding/json" 9 "encoding/json"
10 "flag" 10 "flag"
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } 649 }
650 return buf.Bytes() 650 return buf.Bytes()
651 } 651 }
652 652
653 func redirect(w http.ResponseWriter, r *http.Request) (redirected bool) { 653 func redirect(w http.ResponseWriter, r *http.Request) (redirected bool) {
654 canonical := pathpkg.Clean(r.URL.Path) 654 canonical := pathpkg.Clean(r.URL.Path)
655 if !strings.HasSuffix("/", canonical) { 655 if !strings.HasSuffix("/", canonical) {
656 canonical += "/" 656 canonical += "/"
657 } 657 }
658 if r.URL.Path != canonical { 658 if r.URL.Path != canonical {
659 » » http.Redirect(w, r, canonical, http.StatusMovedPermanently) 659 » » url := *r.URL
660 » » url.Path = canonical
661 » » http.Redirect(w, r, url.String(), http.StatusMovedPermanently)
660 redirected = true 662 redirected = true
661 } 663 }
662 return 664 return
663 } 665 }
664 666
665 func redirectFile(w http.ResponseWriter, r *http.Request) (redirected bool) { 667 func redirectFile(w http.ResponseWriter, r *http.Request) (redirected bool) {
666 c := pathpkg.Clean(r.URL.Path) 668 c := pathpkg.Clean(r.URL.Path)
667 for strings.HasSuffix("/", c) { 669 for strings.HasSuffix("/", c) {
668 c = c[:len(c)-1] 670 c = c[:len(c)-1]
669 } 671 }
670 if r.URL.Path != c { 672 if r.URL.Path != c {
671 » » http.Redirect(w, r, c, http.StatusMovedPermanently) 673 » » url := *r.URL
674 » » url.Path = c
675 » » http.Redirect(w, r, url.String(), http.StatusMovedPermanently)
672 redirected = true 676 redirected = true
673 } 677 }
674 return 678 return
675 } 679 }
676 680
677 func serveTextFile(w http.ResponseWriter, r *http.Request, abspath, relpath, tit le string) { 681 func serveTextFile(w http.ResponseWriter, r *http.Request, abspath, relpath, tit le string) {
678 src, err := ReadFile(fs, abspath) 682 src, err := ReadFile(fs, abspath)
679 if err != nil { 683 if err != nil {
680 log.Printf("ReadFile: %s", err) 684 log.Printf("ReadFile: %s", err)
681 serveError(w, r, relpath, err) 685 serveError(w, r, relpath, err)
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 return PageInfo{Dirname: abspath, Err: err} 1042 return PageInfo{Dirname: abspath, Err: err}
1039 } 1043 }
1040 1044
1041 // select package 1045 // select package
1042 var pkg *ast.Package // selected package 1046 var pkg *ast.Package // selected package
1043 if len(pkgs) == 1 { 1047 if len(pkgs) == 1 {
1044 // Exactly one package - select it. 1048 // Exactly one package - select it.
1045 for name, p := range pkgs { 1049 for name, p := range pkgs {
1046 if name != fakePkgName && !h.isPkg { 1050 if name != fakePkgName && !h.isPkg {
1047 // If doc.go is not in package documentation 1051 // If doc.go is not in package documentation
1048 // then it is not usable as command docs. 1052 // then it is not usable as command docs.
rsc 2013/01/22 21:46:20 This is not true. A Go command can be in package m
adg 2013/01/23 05:58:30 If isPkg is false then we're looking for doc.go wi
1049 return PageInfo{ 1053 return PageInfo{
1050 Err: fmt.Errorf("%s is in package %s, no t package %s", fakePkgFile, name, fakePkgName), 1054 Err: fmt.Errorf("%s is in package %s, no t package %s", fakePkgFile, name, fakePkgName),
1051 } 1055 }
1052 } 1056 }
1053 pkg = p 1057 pkg = p
1054 } 1058 }
1055 } else if len(pkgs) > 1 { 1059 } else if len(pkgs) > 1 {
1056 // More than one package - report an error. 1060 // More than one package - report an error.
1057 var buf bytes.Buffer 1061 var buf bytes.Buffer
1058 for _, p := range pkgs { 1062 for _, p := range pkgs {
1059 if buf.Len() > 0 { 1063 if buf.Len() > 0 {
1060 fmt.Fprintf(&buf, ", ") 1064 fmt.Fprintf(&buf, ", ")
1061 } 1065 }
1062 fmt.Fprintf(&buf, p.Name) 1066 fmt.Fprintf(&buf, p.Name)
1063 } 1067 }
1064 return PageInfo{ 1068 return PageInfo{
1065 Dirname: abspath, 1069 Dirname: abspath,
1066 Err: fmt.Errorf("%s contains more than one package: %s", abspath, buf.Bytes()), 1070 Err: fmt.Errorf("%s contains more than one package: %s", abspath, buf.Bytes()),
1067 } 1071 }
1068 } 1072 }
1069 1073
1070 » examples, err := parseExamples(fset, pkgs, abspath) 1074 » var examples []*doc.Example
1071 » if err != nil { 1075 » if h.isPkg {
1072 » » log.Println("parsing examples:", err) 1076 » » examples, err = parseExamples(fset, pkgs, abspath)
1077 » » if err != nil {
1078 » » » log.Println("parsing examples:", err)
1079 » » }
1073 } 1080 }
1074 1081
1075 // compute package documentation 1082 // compute package documentation
1076 var past *ast.File 1083 var past *ast.File
1077 var pdoc *doc.Package 1084 var pdoc *doc.Package
1078 if pkg != nil { 1085 if pkg != nil {
1079 if mode&showSource == 0 { 1086 if mode&showSource == 0 {
1080 // show extracted documentation 1087 // show extracted documentation
1081 var m doc.Mode 1088 var m doc.Mode
1082 if mode&noFiltering != 0 { 1089 if mode&noFiltering != 0 {
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 updateIndex() 1523 updateIndex()
1517 } 1524 }
1518 delay := 60 * time.Second // by default, try every 60s 1525 delay := 60 * time.Second // by default, try every 60s
1519 if *testDir != "" { 1526 if *testDir != "" {
1520 // in test mode, try once a second for fast startup 1527 // in test mode, try once a second for fast startup
1521 delay = 1 * time.Second 1528 delay = 1 * time.Second
1522 } 1529 }
1523 time.Sleep(delay) 1530 time.Sleep(delay)
1524 } 1531 }
1525 } 1532 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b