func Search(ctx *middleware.Context) { q := ctx.Query("q") if ctx.Query("auto_redirect") == "true" && (base.IsGoRepoPath(q) || base.IsGAERepoPath(q) || base.IsValidRemotePath(q)) { ctx.Redirect("/" + q) return } var ( results []*models.PkgInfo err error ) switch q { case "gorepos": results, err = models.GetGoRepos() case "gosubrepos": results, err = models.GetGoSubepos() case "gaesdk": results, err = models.GetGAERepos() default: results, err = models.SearchPkgInfo(100, q) } if err != nil { ctx.Flash.Error(err.Error(), true) } else { ctx.Data["Results"] = results } ctx.Data["Keyword"] = q ctx.HTML(200, SEARCH) }
func crawlDoc(importPath, etag string) (pdoc *Package, err error) { switch { case base.IsGoRepoPath(importPath): pdoc, err = getGolangDoc(importPath, etag) case base.IsValidRemotePath(importPath): pdoc, err = getStatic(importPath, etag) if err == ErrNoServiceMatch { pdoc, err = getDynamic(importPath, etag) } default: err = ErrInvalidRemotePath } if err != nil { return nil, err } // Render README. for name, content := range pdoc.Readme { p, err := httplib.Post("https://api.github.com/markdown/raw?"+setting.GitHubCredentials). Header("Content-Type", "text/plain").Body(content).Bytes() if err != nil { return nil, fmt.Errorf("error rendering README: %v", err) } pdoc.Readme[name] = p } return pdoc, nil }
func Search(ctx *middleware.Context) { q := ctx.Query("q") if ctx.Query("auto_redirect") == "true" && (base.IsGoRepoPath(q) || base.IsValidRemotePath(q)) { ctx.Redirect("/" + q) return } results, err := models.SearchPkgInfo(100, q) if err != nil { ctx.Flash.Error(err.Error(), true) } else { ctx.Data["Results"] = results } ctx.Data["Keyword"] = q ctx.HTML(200, SEARCH) }
func updatePkgRef(pid int64, refPath string) error { if base.IsGoRepoPath(refPath) || refPath == "C" || refPath[1] == '.' || !base.IsValidRemotePath(refPath) { return nil } ref := new(PkgRef) has, err := x.Where("import_path=?", refPath).Get(ref) if err != nil { return fmt.Errorf("get PkgRef: %v", err) } queryStr := "$" + com.ToStr(pid) + "|" if !has { if _, err = x.Insert(&PkgRef{ ImportPath: refPath, RefNum: 1, RefIDs: queryStr, }); err != nil { return fmt.Errorf("insert PkgRef: %v", err) } return nil } i := strings.Index(ref.RefIDs, queryStr) if i > -1 { return nil } ref.RefIDs += queryStr ref.RefNum++ _, err = x.Id(ref.ID).AllCols().Update(ref) return err }