本文整理汇总了Golang中github.com/Unknwon/orbiter/modules/context.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ViewWebhook
func ViewWebhook(ctx *context.Context) {
ctx.Data["Title"] = "View Webhook"
ctx.Data["PageIsWebhook"] = true
ctx.Data["RequireHighlightJS"] = true
webhook, err := models.GetWebhookByID(ctx.ParamsInt64(":id"))
if err != nil {
if errors.IsWebhookNotFound(err) {
ctx.Handle(404, "GetWebhookByID", nil)
} else {
ctx.Handle(500, "GetWebhookByID", err)
}
return
}
ctx.Data["Webhook"] = webhook
// Prettify JSON in case it is not.
buf := new(bytes.Buffer)
if err = json.Indent(buf, []byte(webhook.Payload), "", " "); err != nil {
ctx.Handle(500, "json.Indent", err)
return
}
webhook.Payload = buf.String()
ctx.HTML(200, "webhook/view")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:26,代码来源:webhook.go
示例2: Dashboard
func Dashboard(ctx *context.Context) {
ctx.Data["Title"] = "Dashboard"
ctx.Data["PageIsDashboard"] = true
ctx.Data["NumWebhooks"] = models.CountWebhook()
ctx.HTML(200, "dashboard")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:8,代码来源:dashboard.go
示例3: EditCollector
func EditCollector(ctx *context.Context) {
ctx.Data["Title"] = "Edit Collector"
ctx.Data["PageIsCollector"] = true
parseCollectorByID(ctx)
if ctx.Written() {
return
}
ctx.HTML(200, "collector/edit")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:11,代码来源:collector.go
示例4: EditApplication
func EditApplication(ctx *context.Context) {
ctx.Data["Title"] = "Edit Application"
ctx.Data["PageIsApplication"] = true
parseApplicationByID(ctx)
if ctx.Written() {
return
}
ctx.HTML(200, "application/edit")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:11,代码来源:application.go
示例5: Applications
func Applications(ctx *context.Context) {
ctx.Data["Title"] = "Applications"
ctx.Data["PageIsApplication"] = true
apps, err := models.ListApplications()
if err != nil {
ctx.Handle(500, "ListApplications", err)
return
}
ctx.Data["Applications"] = apps
ctx.HTML(200, "application/list")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:13,代码来源:application.go
示例6: Collectors
func Collectors(ctx *context.Context) {
ctx.Data["Title"] = "Collectors"
ctx.Data["PageIsCollector"] = true
collectors, err := models.ListCollectors()
if err != nil {
ctx.Error(500, err.Error())
return
}
ctx.Data["Collectors"] = collectors
ctx.HTML(200, "collector/list")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:13,代码来源:collector.go
示例7: RegenerateApplicationSecret
func RegenerateApplicationSecret(ctx *context.Context) {
if err := models.RegenerateApplicationToken(ctx.ParamsInt64(":id")); err != nil {
ctx.Error(500, err.Error())
return
}
ctx.Redirect(fmt.Sprintf("/applications/%d", ctx.ParamsInt64(":id")))
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:8,代码来源:application.go
示例8: RegenerateCollectorSecret
func RegenerateCollectorSecret(ctx *context.Context) {
if err := models.RegenerateCollectorSecret(ctx.ParamsInt64(":id")); err != nil {
ctx.Error(500, err.Error())
return
}
ctx.Redirect(fmt.Sprintf("/collectors/%d", ctx.ParamsInt64(":id")))
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:8,代码来源:collector.go
示例9: Webhooks
func Webhooks(ctx *context.Context) {
ctx.Data["Title"] = "Webhooks"
ctx.Data["PageIsWebhook"] = true
webhooks, err := models.QueryWebhooks(models.QueryWebhookOptions{
Limit: 50,
Order: "created desc",
})
if err != nil {
ctx.Error(500, err.Error())
return
}
ctx.Data["Webhooks"] = webhooks
ctx.HTML(200, "webhook/list")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:16,代码来源:webhook.go
示例10: NewCollectorPost
func NewCollectorPost(ctx *context.Context, form NewCollectorForm) {
ctx.Data["Title"] = "New Collector"
ctx.Data["PageIsCollector"] = true
if ctx.HasError() {
ctx.HTML(200, "collector/new")
return
}
collector, err := models.NewCollector(form.Name, models.COLLECT_TYPE_GITHUB)
if err != nil {
if errors.IsCollectorExists(err) {
ctx.Data["Err_Name"] = true
ctx.RenderWithErr("Collector name has been used.", "collector/new", form)
} else {
ctx.Handle(500, "NewCollector", err)
}
return
}
ctx.Redirect(fmt.Sprintf("/collectors/%d", collector.ID))
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:22,代码来源:collector.go
示例11: NewApplicationPost
func NewApplicationPost(ctx *context.Context, form NewApplicationForm) {
ctx.Data["Title"] = "New Application"
ctx.Data["PageIsApplication"] = true
if ctx.HasError() {
ctx.HTML(200, "application/new")
return
}
app, err := models.NewApplication(form.Name)
if err != nil {
if errors.IsApplicationExists(err) {
ctx.Data["Err_Name"] = true
ctx.RenderWithErr("Application name has been used.", "application/new", form)
} else {
ctx.Handle(500, "NewApplication", err)
}
return
}
ctx.Redirect(fmt.Sprintf("/applications/%d", app.ID))
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:22,代码来源:application.go
示例12: DeleteApplication
func DeleteApplication(ctx *context.Context) {
if err := models.DeleteApplicationByID(ctx.ParamsInt64(":id")); err != nil {
ctx.Error(500, err.Error())
return
}
ctx.Redirect("/applications")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:8,代码来源:application.go
示例13: DeleteCollector
func DeleteCollector(ctx *context.Context) {
if err := models.DeleteCollectorByID(ctx.ParamsInt64(":id")); err != nil {
ctx.Error(500, err.Error())
return
}
ctx.Redirect("/collectors")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:8,代码来源:collector.go
示例14: parseApplicationByID
func parseApplicationByID(ctx *context.Context) *models.Application {
app, err := models.GetApplicationByID(ctx.ParamsInt64(":id"))
if err != nil {
if errors.IsApplicationNotFound(err) {
ctx.Handle(404, "EditApplication", nil)
} else {
ctx.Handle(500, "GetApplicationByID", err)
}
return nil
}
ctx.Data["Application"] = app
return app
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:13,代码来源:application.go
示例15: parseCollectorByID
func parseCollectorByID(ctx *context.Context) *models.Collector {
collector, err := models.GetCollectorByID(ctx.ParamsInt64(":id"))
if err != nil {
if errors.IsCollectorNotFound(err) {
ctx.Handle(404, "EditApplication", nil)
} else {
ctx.Handle(500, "GetCollectorByID", err)
}
return nil
}
ctx.Data["Collector"] = collector
return collector
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:13,代码来源:collector.go
示例16: EditApplicationPost
func EditApplicationPost(ctx *context.Context, form NewApplicationForm) {
ctx.Data["Title"] = "Edit Application"
ctx.Data["PageIsApplication"] = true
app := parseApplicationByID(ctx)
if ctx.Written() {
return
}
app.Name = form.Name
if err := models.UpdateApplication(app); err != nil {
if errors.IsApplicationExists(err) {
ctx.Data["Err_Name"] = true
ctx.RenderWithErr("Application name has been used.", "application/edit", form)
} else {
ctx.Error(500, err.Error())
}
return
}
ctx.Redirect(fmt.Sprintf("/applications/%d", app.ID))
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:22,代码来源:application.go
示例17: EditCollectorPost
func EditCollectorPost(ctx *context.Context, form NewCollectorForm) {
ctx.Data["Title"] = "Edit Collector"
ctx.Data["PageIsCollector"] = true
collector := parseCollectorByID(ctx)
if ctx.Written() {
return
}
collector.Name = form.Name
if err := models.UpdateCollector(collector); err != nil {
if errors.IsCollectorExists(err) {
ctx.Data["Err_Name"] = true
ctx.RenderWithErr("Collector name has been used.", "collector/edit", form)
} else {
ctx.Error(500, err.Error())
}
return
}
ctx.Redirect(fmt.Sprintf("/collectors/%d", collector.ID))
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:22,代码来源:collector.go
示例18: Hook
func Hook(ctx *context.Context) {
collector, err := models.GetCollectorBySecret(ctx.Query("secret"))
if err != nil {
if errors.IsCollectorNotFound(err) {
ctx.Error(403)
} else {
ctx.Error(500, err.Error())
}
return
}
payload, err := ctx.Req.Body().Bytes()
if err != nil {
ctx.Error(500, err.Error())
return
}
// NOTE: Currently only support GitHub
event, err := webhook.ParseGitHubEvent(payload)
if err != nil {
ctx.Error(500, err.Error())
return
}
if err = models.NewWebhook(&models.Webhook{
CollectorID: collector.ID,
Owner: tool.FirstNonEmptyString(event.Repository.Owner.Login, event.Repository.Owner.Name),
RepoName: event.Repository.Name,
EventType: ctx.Req.Header.Get("X-GitHub-Event"),
Sender: event.Sender.Login,
Payload: string(payload),
}); err != nil {
ctx.Error(500, err.Error())
return
}
ctx.Status(202)
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:38,代码来源:hook.go
示例19: NewCollector
func NewCollector(ctx *context.Context) {
ctx.Data["Title"] = "New Collector"
ctx.Data["PageIsCollector"] = true
ctx.HTML(200, "collector/new")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:5,代码来源:collector.go
示例20: Config
func Config(ctx *context.Context) {
ctx.Data["Title"] = "Configuration"
ctx.Data["PageIsConfig"] = true
ctx.HTML(200, "config")
}
开发者ID:Unknwon,项目名称:orbiter,代码行数:5,代码来源:config.go
注:本文中的github.com/Unknwon/orbiter/modules/context.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论