// initPopPros initializes popular projects. func initPopPros() { var err error err, recentUpdatedExs, recentViewedPros, topRankPros, topViewedPros, RockPros = models.GetPopulars(maxProInfoNum, maxExamNum) if err != nil { panic("initPopPros -> " + err.Error()) } }
// initPopPros initializes popular projects. func initPopPros() { var err error err, recentUpdatedExs, recentViewedPros, topRankPros, topViewedPros, RockPros = models.GetPopulars(maxProInfoNum, maxExamNum) if err != nil { log.Fatalf("initPopPros -> %v", err) } }
// initPopPros initializes popular projects. func initPopPros() { popPros := make([][]*models.PkgInfo, 4) var err error err, recentUpdatedExs, popPros[0], popPros[1], popPros[2], popPros[3] = models.GetPopulars(maxProInfoNum, maxExamNum) if err != nil { panic("initPopPros -> " + err.Error()) } for i, ps := range popPros { tmpPros := make([]*proInfo, 0, maxProInfoNum) for _, p := range ps { tmpPros = append(tmpPros, &proInfo{ Pid: p.Id, Path: p.Path, Synopsis: p.Synopsis, IsGoRepo: p.ProName == "Go" && strings.Index(p.Path, ".") == -1, Views: p.Views, ViewedTime: p.ViewedTime, Rank: p.Rank, }) } switch i { case 0: recentViewedPros = tmpPros case 1: topRankPros = tmpPros case 2: topViewedPros = tmpPros case 3: RockPros = tmpPros } } }
// Get implemented Get method for HomeRouter. func (this *HomeRouter) Get() { // Filter unusual User-Agent. ua := this.Ctx.Request.Header.Get("User-Agent") if len(ua) < 20 { beego.Warn("User-Agent:", this.Ctx.Request.Header.Get("User-Agent")) return } // Set language version. curLang := setLangVer(this.Ctx, this.Input(), this.Data) // Get query field. q := strings.TrimSpace(this.Input().Get("q")) // Remove last "/". q = strings.TrimRight(q, "/") if path, ok := utils.IsBrowseURL(q); ok { q = path } // Get pure URL. reqUrl := this.Ctx.Request.RequestURI[1:] if i := strings.Index(reqUrl, "?"); i > -1 { reqUrl = reqUrl[:i] if path, ok := utils.IsBrowseURL(reqUrl); ok { reqUrl = path } } // Redirect to query string. if len(reqUrl) == 0 && len(q) > 0 { reqUrl = q this.Redirect("/"+reqUrl, 302) return } // Check show home page or documentation page. if len(reqUrl) == 0 && len(q) == 0 { // Home page. this.Data["IsHome"] = true this.TplNames = "home_" + curLang.Lang + ".html" // Recent projects this.Data["RecentPros"] = recentViewedPros // Get popular project and examples list from database. this.Data["PopPros"], this.Data["RecentExams"] = models.GetPopulars(20, 12) // Set standard library keyword type-ahead. this.Data["DataSrc"] = utils.GoRepoSet } else { // Documentation page. this.TplNames = "docs_" + curLang.Lang + ".html" broPath := reqUrl // Browse path. // Check if it is standard library. if utils.IsGoRepoPath(broPath) { broPath = "code.google.com/p/go/source/browse/src/pkg/" + broPath } // Check if it is a remote path that can be used for 'gopm get', if not means it's a keyword. if !utils.IsValidRemotePath(broPath) { // Show search page this.Redirect("/search?q="+reqUrl, 302) return } // Get tag field. tag := strings.TrimSpace(this.Input().Get("tag")) if tag == "master" || tag == "default" { tag = "" } // Check documentation of this import path, and update automatically as needed. pdoc, err := doc.CheckDoc(reqUrl, tag, doc.HUMAN_REQUEST) if err == nil || pdoc == nil { pdoc.UserExamples = getUserExamples(pdoc.ImportPath) // Generate documentation page. if generatePage(this, pdoc, broPath, tag, curLang.Lang) { // Update recent project list. updateRecentPros(pdoc) // Update project views. pinfo := &models.PkgInfo{ Path: pdoc.ImportPath, Synopsis: pdoc.Synopsis, Created: pdoc.Created, ProName: pdoc.ProjectName, ViewedTime: pdoc.ViewedTime, Views: pdoc.Views, IsCmd: pdoc.IsCmd, Etag: pdoc.Etag, Labels: pdoc.Labels, Tags: strings.Join(pdoc.Tags, "|||"), ImportedNum: pdoc.ImportedNum, ImportPid: pdoc.ImportPid, } models.AddViews(pinfo) return } } else { beego.Error("HomeRouter.Get ->", err) } // Show search page this.Redirect("/search?q="+reqUrl, 302) return } }