func documentTerms(pdoc *doc.Package, score float64) []string { terms := make(map[string]bool) // Project root projectRoot := normalizeProjectRoot(pdoc.ProjectRoot) terms["project:"+projectRoot] = true if strings.HasPrefix(pdoc.ImportPath, "code.google.com/p/go.") { terms["project:subrepo"] = true } // Imports for _, path := range pdoc.Imports { if gosrc.IsValidPath(path) { terms["import:"+path] = true } } if score > 0 { if isStandardPackage(pdoc.ImportPath) { for _, term := range parseQuery(pdoc.ImportPath) { terms[term] = true } } else { terms["all:"] = true for _, term := range parseQuery(pdoc.ProjectName) { terms[term] = true } for _, term := range parseQuery(pdoc.Name) { terms[term] = true } } // Synopsis synopsis := httpPat.ReplaceAllLiteralString(pdoc.Synopsis, "") for i, s := range strings.FieldsFunc(synopsis, isTermSep) { s = strings.ToLower(s) if !stopWord[s] && (i > 3 || s != "package") { terms[term(s)] = true } } } result := make([]string, 0, len(terms)) for term := range terms { result = append(result, term) } return result }
// commentFn formats a source code comment as HTML. func commentFn(v string) htemp.HTML { var buf bytes.Buffer godoc.ToHTML(&buf, v, nil) p := buf.Bytes() p = replaceAll(p, h3Pat, func(out, src []byte, m []int) []byte { out = append(out, `<h4 id="`...) out = append(out, src[m[2]:m[3]]...) out = append(out, `">`...) out = append(out, src[m[4]:m[5]]...) out = append(out, ` <a class="permalink" href="#`...) out = append(out, src[m[2]:m[3]]...) out = append(out, `">¶</a></h4>`...) return out }) p = replaceAll(p, rfcPat, func(out, src []byte, m []int) []byte { out = append(out, `<a href="http://tools.ietf.org/html/rfc`...) out = append(out, src[m[2]:m[3]]...) // If available, add major section fragment if m[6] != -1 { out = append(out, `#section-`...) out = append(out, src[m[8]:m[9]]...) // If available, add minor section fragment if m[13] != -1 { out = append(out, src[m[12]:m[13]]...) } } out = append(out, `">`...) out = append(out, src[m[0]:m[1]]...) out = append(out, `</a>`...) return out }) p = replaceAll(p, packagePat, func(out, src []byte, m []int) []byte { path := bytes.TrimRight(src[m[2]:m[3]], ".!?:") if !gosrc.IsValidPath(string(path)) { return append(out, src[m[0]:m[1]]...) } out = append(out, src[m[0]:m[2]]...) out = append(out, `<a href="/`...) out = append(out, path...) out = append(out, `">`...) out = append(out, path...) out = append(out, `</a>`...) out = append(out, src[m[2]+len(path):m[1]]...) return out }) return htemp.HTML(p) }
func dangle(c *command) { if len(c.flag.Args()) != 0 { c.printUsage() os.Exit(1) } db, err := database.New() if err != nil { log.Fatal(err) } m := make(map[string]int) err = db.Do(func(pi *database.PackageInfo) error { m[pi.PDoc.ImportPath] |= 1 for _, p := range pi.PDoc.Imports { if gosrc.IsValidPath(p) { m[p] |= 2 } } for _, p := range pi.PDoc.TestImports { if gosrc.IsValidPath(p) { m[p] |= 2 } } for _, p := range pi.PDoc.XTestImports { if gosrc.IsValidPath(p) { m[p] |= 2 } } return nil }) for p, v := range m { if v == 2 { fmt.Println(p) } } }
func documentTerms(pdoc *doc.Package, score float64) []string { terms := make(map[string]bool) // Project root projectRoot := normalizeProjectRoot(pdoc.ProjectRoot) terms["project:"+projectRoot] = true if strings.HasPrefix(pdoc.ImportPath, "golang.org/x/") { terms["project:subrepo"] = true } // Imports for _, path := range pdoc.Imports { if gosrc.IsValidPath(path) { terms["import:"+path] = true } } if score > 0 { if isStandardPackage(pdoc.ImportPath) { for _, term := range parseQuery(pdoc.ImportPath) { terms[term] = true } } else { terms["all:"] = true for _, term := range parseQuery(pdoc.ProjectName) { terms[term] = true } for _, term := range parseQuery(pdoc.Name) { terms[term] = true } } // Synopsis collectSynopsisTerms(terms, pdoc.Synopsis) } return termSlice(terms) }
func (b *builder) vetPackage(pkg *Package, apkg *ast.Package) { errors := make(map[string]token.Pos) for _, file := range apkg.Files { for _, is := range file.Imports { importPath, _ := strconv.Unquote(is.Path.Value) if !gosrc.IsValidPath(importPath) && !strings.HasPrefix(importPath, "exp/") && !strings.HasPrefix(importPath, "appengine") { errors[fmt.Sprintf("Unrecognized import path %q", importPath)] = is.Pos() } } v := vetVisitor{errors: errors} ast.Walk(&v, file) } for message, pos := range errors { pkg.Errors = append(pkg.Errors, fmt.Sprintf("%s (%s)", message, b.fset.Position(pos))) } }
func serveRoot(w http.ResponseWriter, r *http.Request) error { switch { case r.Method != "GET" && r.Method != "HEAD": return writeErrorResponse(w, 405) case r.URL.Path == "/": return writeResponse(w, 200, homeTemplate, nil) default: importPath := r.URL.Path[1:] if !gosrc.IsValidPath(importPath) { return gosrc.NotFoundError{Message: "bad path"} } c := appengine.NewContext(r) pkg, err := getPackage(c, importPath) if pkg == nil && err == nil { pkg, err = runLint(r, importPath) } if err != nil { return err } filterByConfidence(r, pkg) return writeResponse(w, 200, packageTemplate, pkg) } }