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, _ := 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 #2
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
}