当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.QueryInt方法代码示例

本文整理汇总了Golang中github.com/smallnewer/gogs/modules/middleware.Context.QueryInt方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.QueryInt方法的具体用法?Golang Context.QueryInt怎么用?Golang Context.QueryInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/smallnewer/gogs/modules/middleware.Context的用法示例。


在下文中一共展示了Context.QueryInt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Explore

func Explore(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("explore")
	ctx.Data["PageIsExplore"] = true
	ctx.Data["PageIsExploreRepositories"] = true

	page := ctx.QueryInt("page")
	if page <= 1 {
		page = 1
	}

	ctx.Data["Page"] = paginater.New(int(models.CountPublicRepositories()), setting.ExplorePagingNum, page, 5)

	repos, err := models.GetRecentUpdatedRepositories(page)
	if err != nil {
		ctx.Handle(500, "GetRecentUpdatedRepositories", err)
		return
	}
	for _, repo := range repos {
		if err = repo.GetOwner(); err != nil {
			ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err))
			return
		}
	}
	ctx.Data["Repos"] = repos

	ctx.HTML(200, EXPLORE_REPOS)
}
开发者ID:smallnewer,项目名称:gogs,代码行数:27,代码来源:home.go

示例2: Commits

func Commits(ctx *middleware.Context) {
	ctx.Data["PageIsCommits"] = true

	userName := ctx.Repo.Owner.Name
	repoName := ctx.Repo.Repository.Name

	brs, err := ctx.Repo.GitRepo.GetBranches()
	if err != nil {
		ctx.Handle(500, "GetBranches", err)
		return
	} else if len(brs) == 0 {
		ctx.Handle(404, "GetBranches", nil)
		return
	}

	commitsCount, err := ctx.Repo.Commit.CommitsCount()
	if err != nil {
		ctx.Handle(500, "GetCommitsCount", err)
		return
	}

	page := ctx.QueryInt("page")
	if page <= 1 {
		page = 1
	}
	ctx.Data["Page"] = paginater.New(commitsCount, git.CommitsRangeSize, page, 5)

	// Both `git log branchName` and `git log commitId` work.
	commits, err := ctx.Repo.Commit.CommitsByRange(page)
	if err != nil {
		ctx.Handle(500, "CommitsByRange", err)
		return
	}
	commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
	commits = models.ValidateCommitsWithEmails(commits)

	ctx.Data["Commits"] = commits
	ctx.Data["Username"] = userName
	ctx.Data["Reponame"] = repoName
	ctx.Data["CommitCount"] = commitsCount
	ctx.HTML(200, COMMITS)
}
开发者ID:smallnewer,项目名称:gogs,代码行数:42,代码来源:commit.go

示例3: Stars

func Stars(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("repos.stars")

	page := ctx.QueryInt("page")
	if page <= 0 {
		page = 1
	}

	ctx.Data["Page"] = paginater.New(ctx.Repo.Repository.NumStars, models.ItemsPerPage, page, 5)

	stars, err := ctx.Repo.Repository.GetStars(ctx.QueryInt("page"))

	if err != nil {
		ctx.Handle(500, "GetStars", err)
		return
	}

	if (ctx.QueryInt("page")-1)*models.ItemsPerPage > ctx.Repo.Repository.NumStars {
		ctx.Handle(404, "ctx.Repo.Repository.NumStars", nil)
		return
	}

	ctx.Data["Stars"] = stars

	ctx.HTML(200, STARS)
}
开发者ID:smallnewer,项目名称:gogs,代码行数:26,代码来源:stars.go

示例4: Repositories

func Repositories(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("admin.repositories")
	ctx.Data["PageIsAdmin"] = true
	ctx.Data["PageIsAdminRepositories"] = true

	total := models.CountRepositories()
	page := ctx.QueryInt("page")
	if page <= 1 {
		page = 1
	}
	ctx.Data["Page"] = paginater.New(int(total), setting.AdminRepoPagingNum, page, 5)

	repos, err := models.RepositoriesWithUsers(page, setting.AdminRepoPagingNum)
	if err != nil {
		ctx.Handle(500, "RepositoriesWithUsers", err)
		return
	}
	ctx.Data["Repos"] = repos

	ctx.Data["Total"] = total
	ctx.HTML(200, REPOS)
}
开发者ID:smallnewer,项目名称:gogs,代码行数:22,代码来源:repos.go

示例5: Notices

func Notices(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("admin.notices")
	ctx.Data["PageIsAdmin"] = true
	ctx.Data["PageIsAdminNotices"] = true

	total := models.CountNotices()
	page := ctx.QueryInt("page")
	if page <= 1 {
		page = 1
	}
	ctx.Data["Page"] = paginater.New(int(total), setting.AdminNoticePagingNum, page, 5)

	notices, err := models.Notices(page, setting.AdminNoticePagingNum)
	if err != nil {
		ctx.Handle(500, "Notices", err)
		return
	}
	ctx.Data["Notices"] = notices

	ctx.Data["Total"] = total
	ctx.HTML(200, NOTICES)
}
开发者ID:smallnewer,项目名称:gogs,代码行数:22,代码来源:notice.go

示例6: Users

func Users(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("admin.users")
	ctx.Data["PageIsAdmin"] = true
	ctx.Data["PageIsAdminUsers"] = true

	total := models.CountUsers()
	page := ctx.QueryInt("page")
	if page <= 1 {
		page = 1
	}
	ctx.Data["Page"] = paginater.New(int(total), setting.AdminUserPagingNum, page, 5)

	users, err := models.Users(page, setting.AdminUserPagingNum)
	if err != nil {
		ctx.Handle(500, "Users", err)
		return
	}
	ctx.Data["Users"] = users

	ctx.Data["Total"] = total
	ctx.HTML(200, USERS)
}
开发者ID:smallnewer,项目名称:gogs,代码行数:22,代码来源:users.go

示例7: Organizations

func Organizations(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("admin.organizations")
	ctx.Data["PageIsAdmin"] = true
	ctx.Data["PageIsAdminOrganizations"] = true

	total := models.CountOrganizations()
	page := ctx.QueryInt("page")
	if page <= 1 {
		page = 1
	}
	ctx.Data["Page"] = paginater.New(int(total), setting.AdminOrgPagingNum, page, 5)

	orgs, err := models.Organizations(page, setting.AdminOrgPagingNum)

	if err != nil {
		ctx.Handle(500, "Organizations", err)
		return
	}

	ctx.Data["Orgs"] = orgs
	ctx.Data["Total"] = total

	ctx.HTML(200, ORGS)
}
开发者ID:smallnewer,项目名称:gogs,代码行数:24,代码来源:orgs.go

示例8: Issues

func Issues(ctx *middleware.Context) {
	isPullList := ctx.Params(":type") == "pulls"
	if isPullList {
		ctx.Data["Title"] = ctx.Tr("pull_requests")
		ctx.Data["PageIsPulls"] = true
	} else {
		ctx.Data["Title"] = ctx.Tr("issues")
		ctx.Data["PageIsIssues"] = true
	}

	ctxUser := getDashboardContextUser(ctx)
	if ctx.Written() {
		return
	}

	// Organization does not have view type and filter mode.
	var (
		viewType   string
		filterMode = models.FM_ALL
		assigneeID int64
		posterID   int64
	)
	if ctxUser.IsOrganization() {
		viewType = "all"
	} else {
		viewType = ctx.Query("type")
		types := []string{"assigned", "created_by"}
		if !com.IsSliceContainsStr(types, viewType) {
			viewType = "all"
		}

		switch viewType {
		case "assigned":
			filterMode = models.FM_ASSIGN
			assigneeID = ctxUser.Id
		case "created_by":
			filterMode = models.FM_CREATE
			posterID = ctxUser.Id
		}
	}

	repoID := ctx.QueryInt64("repo")
	isShowClosed := ctx.Query("state") == "closed"

	// Get repositories.
	repos, err := models.GetRepositories(ctxUser.Id, true)
	if err != nil {
		ctx.Handle(500, "GetRepositories", err)
		return
	}

	allCount := 0
	repoIDs := make([]int64, 0, len(repos))
	showRepos := make([]*models.Repository, 0, len(repos))
	for _, repo := range repos {
		if (isPullList && repo.NumPulls == 0) ||
			(!isPullList && repo.NumIssues == 0) {
			continue
		}

		repoIDs = append(repoIDs, repo.ID)

		if isPullList {
			allCount += repo.NumOpenPulls
			repo.NumOpenIssues = repo.NumOpenPulls
			repo.NumClosedIssues = repo.NumClosedPulls
		} else {
			allCount += repo.NumOpenIssues
		}

		if filterMode != models.FM_ALL {
			// Calculate repository issue count with filter mode.
			numOpen, numClosed := repo.IssueStats(ctxUser.Id, filterMode, isPullList)
			repo.NumOpenIssues, repo.NumClosedIssues = int(numOpen), int(numClosed)
		}

		if repo.ID == repoID ||
			(isShowClosed && repo.NumClosedIssues > 0) ||
			(!isShowClosed && repo.NumOpenIssues > 0) {
			showRepos = append(showRepos, repo)
		}
	}
	ctx.Data["Repos"] = showRepos

	issueStats := models.GetUserIssueStats(repoID, ctxUser.Id, repoIDs, filterMode, isPullList)
	issueStats.AllCount = int64(allCount)

	page := ctx.QueryInt("page")
	if page <= 1 {
		page = 1
	}

	var total int
	if !isShowClosed {
		total = int(issueStats.OpenCount)
	} else {
		total = int(issueStats.ClosedCount)
	}
	ctx.Data["Page"] = paginater.New(total, setting.IssuePagingNum, page, 5)

//.........这里部分代码省略.........
开发者ID:smallnewer,项目名称:gogs,代码行数:101,代码来源:home.go


注:本文中的github.com/smallnewer/gogs/modules/middleware.Context.QueryInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。