Exemplo n.º 1
0
// getHistory returns browse history.
func getHistory(ctx *middleware.Context) []*models.PkgInfo {
	pairs := strings.Split(ctx.GetCookie("user_history"), "|")
	pkgs := make([]*models.PkgInfo, 0, len(pairs))

	for _, pair := range pairs {
		infos := strings.Split(pair, ":")
		if len(infos) != 2 {
			continue
		}

		pid := com.StrTo(infos[0]).MustInt64()
		if pid == 0 {
			continue
		}

		pinfo, _ := models.GetPkgInfoById(pid)
		if pinfo == nil {
			continue
		}

		pinfo.LastView = com.StrTo(infos[1]).MustInt64()
		pkgs = append(pkgs, pinfo)
	}
	return pkgs
}
Exemplo n.º 2
0
// checkSpecialUsage checks special usage of keywords.
// It returns true if it is a special usage, false otherwise.
func checkSpecialUsage(this *SearchController, q string) bool {
	switch {
	case q == "gorepo":
		// Show list of standard library.
		pkgInfos, _ := models.GetGoRepo()
		// Show results after searched.
		if len(pkgInfos) > 0 {
			this.Data["IsFindPro"] = true
			this.Data["AllPros"] = pkgInfos
		}
		return true
	case q == "imports":
		// Show imports package list.
		pkgs := strings.Split(this.Input().Get("pkgs"), "|")
		pinfos := make([]*models.PkgInfo, 0, len(pkgs)-1)
		for _, v := range pkgs {
			if pinfo, err := models.GetPkgInfo(v); err == nil {
				pinfos = append(pinfos, pinfo)
			} else {
				pinfos = append(pinfos, &models.PkgInfo{Path: v})
			}
		}

		if len(pinfos) > 0 {
			this.Data["IsFindPro"] = true
			this.Data["AllPros"] = pinfos
		}
		return true
	case q == "imported":
		// Show packages that import this project.
		pkgs := strings.Split(this.Input().Get("pkgs"), "|")
		pinfos := make([]*models.PkgInfo, 0, len(pkgs)-1)
		for _, v := range pkgs {
			if len(v) > 1 {
				id, _ := strconv.Atoi(v[1:])
				if pinfo, err := models.GetPkgInfoById(id); err == nil {
					pinfos = append(pinfos, pinfo)
				}

			}
		}

		if len(pinfos) > 0 {
			this.Data["IsFindPro"] = true
			this.Data["AllPros"] = pinfos
		}
		return true
	}

	return false
}