Example #1
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, 15)
		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
	}

	return false
}
Example #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, _ := models.GetGroupPkgInfo(pkgs)
		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, _ := models.GetGroupPkgInfoById(pkgs)
		if len(pinfos) > 0 {
			this.Data["IsFindPro"] = true
			this.Data["AllPros"] = pinfos
		}
		return true
	case strings.Index(q, ":tag=") > -1: // Add tag(s) to the project.
		// Get tag(s).
		i := strings.Index(q, ":tag=")
		if utils.IsGoRepoPath(q[:i]) {
			this.Redirect("/"+q[:i], 302)
			return true
		}

		if isTag(q[i+5:]) && models.UpdateTagInfo(q[:i], q[i+5:], true) {
			this.Redirect("/"+q[:i], 302)
		}
		return true
	case strings.Index(q, ":rtag=") > -1: // Remove tag(s) to the project.
		// Get tag(s).
		i := strings.Index(q, ":rtag=")
		if utils.IsGoRepoPath(q[:i]) {
			this.Redirect("/"+q[:i], 302)
			return true
		}

		if isTag(q[i+6:]) && models.UpdateTagInfo(q[:i], q[i+6:], false) {
			this.Redirect("/"+q[:i], 302)
		}
		return true
	}

	return false
}
Example #3
0
// checkSpecialUsage checks special usage of keywords.
// It returns true if it is a special usage, false otherwise.
func checkSpecialUsage(this *SearchRouter, q string) bool {
	switch {
	case q == "gorepo": // Show list of standard library.
		pinfos, _ := models.GetGoRepo()
		if len(pinfos) > 0 {
			this.Data["IsFindPro"] = true
			this.Data["Results"] = pinfos
		}
		return true
	case q == "imports": // Show imports package list.
		pkgs := strings.Split(this.Input().Get("pkgs"), "|")
		pinfos, _ := models.GetGroupPkgInfo(pkgs)
		if len(pinfos) > 0 {
			this.Data["IsFindPro"] = true
			this.Data["Results"] = pinfos
		}
		return true
	case q == "imported": // Show packages that import this project.
		pkgs := strings.Split(
			strings.Replace(this.Input().Get("pkgs"), "$", "", -1), "|")
		pinfos := models.GetGroupPkgInfoById(pkgs)
		if len(pinfos) > 0 {
			this.Data["IsFindPro"] = true
			this.Data["Results"] = pinfos
		}
		return true
	case strings.Index(q, ":l=") > -1: // Add label to the project.
		// Get label(s).
		i := strings.Index(q, ":l=")
		if utils.IsGoRepoPath(q[:i]) {
			this.Redirect("/"+q[:i], 302)
			return true
		}

		if isLabel(q[i+3:]) && models.UpdateLabelInfo(q[:i], q[i+3:], true) {
			this.Redirect("/"+q[:i], 302)
		}
		return true
	case strings.Index(q, ":rl=") > -1: // Remove label to the project.
		// Get label(s).
		i := strings.Index(q, ":rl=")
		if utils.IsGoRepoPath(q[:i]) {
			this.Redirect("/"+q[:i], 302)
			return true
		}

		if isLabel(q[i+4:]) && models.UpdateLabelInfo(q[:i], q[i+4:], false) {
			this.Redirect("/"+q[:i], 302)
		}
		return true
	}

	return false
}
Example #4
0
func checkSpecialUsage(this *SearchRouter, q, t, pid, tag string) bool {
	var pinfos []*hv.PkgInfo

	switch {
	case t == "imports":
		pinfos = models.GetImports(pid, tag)
	case t == "refs":
		pinfos = models.GetRefs(pid)
	case q == "gorepos":
		pinfos = models.GetGoRepo()
	case q == "gosubrepos":
		pinfos = models.GetGoSubrepo()
	}

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

	return false
}