本文整理汇总了Golang中github.com/smallnewer/gogs/modules/middleware.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: EditTeam
func EditTeam(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true
ctx.Data["team_name"] = ctx.Org.Team.Name
ctx.Data["desc"] = ctx.Org.Team.Description
ctx.HTML(200, TEAM_NEW)
}
示例2: 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)
}
示例3: NewTeam
func NewTeam(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true
ctx.Data["PageIsOrgTeamsNew"] = true
ctx.Data["Team"] = &models.Team{}
ctx.HTML(200, TEAM_NEW)
}
示例4: checkWebhook
func checkWebhook(ctx *middleware.Context) (*OrgRepoCtx, *models.Webhook) {
ctx.Data["RequireHighlightJS"] = true
orCtx, err := getOrgRepoCtx(ctx)
if err != nil {
ctx.Handle(500, "getOrgRepoCtx", err)
return nil, nil
}
ctx.Data["BaseLink"] = orCtx.Link
w, err := models.GetWebhookByID(ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrWebhookNotExist(err) {
ctx.Handle(404, "GetWebhookByID", nil)
} else {
ctx.Handle(500, "GetWebhookByID", err)
}
return nil, nil
}
switch w.HookTaskType {
case models.SLACK:
ctx.Data["SlackHook"] = w.GetSlackHook()
ctx.Data["HookType"] = "slack"
default:
ctx.Data["HookType"] = "gogs"
}
ctx.Data["History"], err = w.History(1)
if err != nil {
ctx.Handle(500, "History", err)
}
return orCtx, w
}
示例5: Install
func Install(ctx *middleware.Context) {
form := auth.InstallForm{}
// Database settings
form.DbHost = models.DbCfg.Host
form.DbUser = models.DbCfg.User
form.DbName = models.DbCfg.Name
form.DbPath = models.DbCfg.Path
ctx.Data["CurDbOption"] = "MySQL"
switch models.DbCfg.Type {
case "postgres":
ctx.Data["CurDbOption"] = "PostgreSQL"
case "sqlite3":
if models.EnableSQLite3 {
ctx.Data["CurDbOption"] = "SQLite3"
}
case "tidb":
if models.EnableTidb {
ctx.Data["CurDbOption"] = "TiDB"
}
}
// Application general settings
form.AppName = setting.AppName
form.RepoRootPath = setting.RepoRootPath
// Note(unknwon): it's hard for Windows users change a running user,
// so just use current one if config says default.
if setting.IsWindows && setting.RunUser == "git" {
form.RunUser = user.CurrentUsername()
} else {
form.RunUser = setting.RunUser
}
form.Domain = setting.Domain
form.SSHPort = setting.SSHPort
form.HTTPPort = setting.HttpPort
form.AppUrl = setting.AppUrl
// E-mail service settings
if setting.MailService != nil {
form.SMTPHost = setting.MailService.Host
form.SMTPFrom = setting.MailService.From
form.SMTPEmail = setting.MailService.User
}
form.RegisterConfirm = setting.Service.RegisterEmailConfirm
form.MailNotify = setting.Service.EnableNotifyMail
// Server and other services settings
form.OfflineMode = setting.OfflineMode
form.DisableGravatar = setting.DisableGravatar
form.DisableRegistration = setting.Service.DisableRegistration
form.EnableCaptcha = setting.Service.EnableCaptcha
form.RequireSignInView = setting.Service.RequireSignInView
auth.AssignForm(form, ctx.Data)
ctx.HTML(200, INSTALL)
}
示例6: Monitor
func Monitor(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("admin.monitor")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminMonitor"] = true
ctx.Data["Processes"] = process.Processes
ctx.Data["Entries"] = cron.ListTasks()
ctx.HTML(200, MONITOR)
}
示例7: checkHookType
func checkHookType(ctx *middleware.Context) string {
hookType := strings.ToLower(ctx.Params(":type"))
if !com.IsSliceContainsStr(setting.Webhook.Types, hookType) {
ctx.Handle(404, "checkHookType", nil)
return ""
}
return hookType
}
示例8: CreateRepo
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create
func CreateRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
// Shouldn't reach this condition, but just in case.
if ctx.User.IsOrganization() {
ctx.APIError(422, "", "not allowed creating repository for organization")
return
}
createRepo(ctx, ctx.User, opt)
}
示例9: MarkdownRaw
// Render a Markdown document in raw mode.
func MarkdownRaw(ctx *middleware.Context) {
body, err := ctx.Req.Body().Bytes()
if err != nil {
ctx.APIError(422, "", err)
return
}
ctx.Write(base.RenderRawMarkdown(body, ""))
}
示例10: TeamRepositories
func TeamRepositories(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true
if err := ctx.Org.Team.GetRepositories(); err != nil {
ctx.Handle(500, "GetRepositories", err)
return
}
ctx.HTML(200, TEAM_REPOSITORIES)
}
示例11: TeamMembers
func TeamMembers(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Org.Team.Name
ctx.Data["PageIsOrgTeams"] = true
if err := ctx.Org.Team.GetMembers(); err != nil {
ctx.Handle(500, "GetMembers", err)
return
}
ctx.HTML(200, TEAM_MEMBERS)
}
示例12: SettingsAvatar
func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
form.Enable = true
if err := user.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil {
ctx.Flash.Error(err.Error())
} else {
ctx.Flash.Success(ctx.Tr("org.settings.update_avatar_success"))
}
ctx.Redirect(ctx.Org.OrgLink + "/settings")
}
示例13: CreateAccessToken
// POST /users/:username/tokens
func CreateAccessToken(ctx *middleware.Context, form CreateAccessTokenForm) {
t := &models.AccessToken{
UID: ctx.User.Id,
Name: form.Name,
}
if err := models.NewAccessToken(t); err != nil {
ctx.APIError(500, "NewAccessToken", err)
return
}
ctx.JSON(201, &api.AccessToken{t.Name, t.Sha1})
}
示例14: TemplatePreview
func TemplatePreview(ctx *middleware.Context) {
ctx.Data["User"] = models.User{Name: "Unknown"}
ctx.Data["AppName"] = setting.AppName
ctx.Data["AppVer"] = setting.AppVer
ctx.Data["AppUrl"] = setting.AppUrl
ctx.Data["Code"] = "2014031910370000009fff6782aadb2162b4a997acb69d4400888e0b9274657374"
ctx.Data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60
ctx.Data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60
ctx.Data["CurDbValue"] = ""
ctx.HTML(200, base.TplName(ctx.Params("*")))
}
示例15: ListAccessTokens
// GET /users/:username/tokens
func ListAccessTokens(ctx *middleware.Context) {
tokens, err := models.ListAccessTokens(ctx.User.Id)
if err != nil {
ctx.APIError(500, "ListAccessTokens", err)
return
}
apiTokens := make([]*api.AccessToken, len(tokens))
for i := range tokens {
apiTokens[i] = &api.AccessToken{tokens[i].Name, tokens[i].Sha1}
}
ctx.JSON(200, &apiTokens)
}