本文整理汇总了Golang中github.com/gpmgo/switch/modules/middleware.Context.Handle方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Handle方法的具体用法?Golang Context.Handle怎么用?Golang Context.Handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/gpmgo/switch/modules/middleware.Context
的用法示例。
在下文中一共展示了Context.Handle方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BlockPackagePost
func BlockPackagePost(ctx *middleware.Context) {
ctx.Data["PageIsBlocks"] = true
ctx.Data["PageIsBlocksList"] = true
keys, err := models.BlockPackage(ctx.Query("import_path"), ctx.Query("note"))
if err != nil {
if err == models.ErrPackageNotExist {
ctx.RenderWithErr(err.Error(), "blocks/new", nil)
} else {
ctx.Handle(500, "BlockPackage", err)
}
return
}
if setting.ProdMode {
for _, k := range keys {
log.Trace("Deleting archive: %s", k)
if err = qiniu.DeleteArchive(k); err != nil {
log.Error(4, "Fail to delete archive(%s): %v", k, err)
}
log.Info("Archive deleted: %s", k)
}
}
ctx.Flash.Success("New package has been blocked!")
ctx.Redirect("/admin/blocks")
}
示例2: UnblockPackage
func UnblockPackage(ctx *middleware.Context) {
ctx.Data["PageIsBlocks"] = true
ctx.Data["PageIsBlocksList"] = true
if err := models.UnblockPackage(ctx.ParamsInt64(":id")); err != nil {
ctx.Handle(500, "UnblockPackage", err)
return
}
ctx.Flash.Success("Package has been unblocked!")
ctx.Redirect("/admin/blocks")
}
示例3: DeleteBlockRule
func DeleteBlockRule(ctx *middleware.Context) {
ctx.Data["PageIsBlocks"] = true
ctx.Data["PageIsBlocksRules"] = true
if err := models.DeleteBlockRule(ctx.ParamsInt64(":id")); err != nil {
ctx.Handle(500, "DeleteBlockRule", err)
return
}
ctx.Flash.Success("Block rule has been deleted!")
ctx.Redirect("/admin/blocks/rules")
}
示例4: Search
func Search(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Locale.Tr("search")
ctx.Data["SearchKeyword"] = ctx.Query("q")
pkgs, err := models.SearchPackages(ctx.Query("q"))
if err != nil {
ctx.Handle(500, "SearchPackages", err)
return
}
ctx.Data["ResultPackages"] = pkgs
ctx.HTML(200, "search")
}
示例5: BlockRules
func BlockRules(ctx *middleware.Context) {
ctx.Data["PageIsBlocks"] = true
ctx.Data["PageIsBlocksRules"] = true
rules, err := models.ListBlockRules(0)
if err != nil {
ctx.Handle(500, "ListBlockRules", err)
return
}
ctx.Data["Rules"] = rules
ctx.HTML(200, "blocks/rules")
}
示例6: Blocks
func Blocks(ctx *middleware.Context) {
ctx.Data["PageIsBlocks"] = true
ctx.Data["PageIsBlocksList"] = true
blocks, err := models.ListBlockedPackages(0)
if err != nil {
ctx.Handle(500, "ListBlockedPackages", err)
return
}
ctx.Data["Blocks"] = blocks
ctx.HTML(200, "blocks/list")
}
示例7: Badge
func Badge(ctx *middleware.Context) {
importPath := ctx.Params("*")
pkg, err := models.GetPakcageByPath(importPath)
if err != nil {
if err == models.ErrPackageNotExist {
ctx.Error(404)
} else {
ctx.Handle(500, "Badge", err)
}
return
}
ctx.Redirect(fmt.Sprintf("http://img.shields.io/badge/downloads-%d_total-blue.svg?style=flat", pkg.DownloadCount))
}
示例8: NewBlockRulePost
func NewBlockRulePost(ctx *middleware.Context) {
ctx.Data["PageIsBlocks"] = true
ctx.Data["PageIsBlocksRules"] = true
r := &models.BlockRule{
Rule: ctx.Query("rule"),
Note: ctx.Query("note"),
}
if err := models.NewBlockRule(r); err != nil {
ctx.Handle(500, "NewBlockRule", err)
return
}
ctx.Flash.Success("New block rule has been added!")
ctx.Redirect("/admin/blocks/rules")
}
示例9: Package
func Package(ctx *middleware.Context) {
importPath := ctx.Params("*")
_, err := models.GetPakcageByPath(importPath)
if err != nil {
if err == models.ErrPackageNotExist {
ctx.Handle(404, "Package", nil)
} else {
ctx.Handle(500, "Package", err)
}
return
}
ctx.Data["Title"] = importPath
ctx.Data["ImportPath"] = importPath
ctx.HTML(200, "package")
}
示例10: Download
func Download(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("download")
ctx.Data["PageIsDownload"] = true
importPath := archive.GetRootPath(ctx.Query("pkgname"))
if ctx.Req.Method == "POST" {
rev := ctx.Query("revision")
r, err := models.CheckPkg(importPath, rev)
if err != nil {
ctx.Data["pkgname"] = importPath
ctx.Data["revision"] = rev
errMsg := err.Error()
if err == archive.ErrNotMatchAnyService {
ctx.Data["Err_PkgName"] = true
errMsg = ctx.Tr("download.err_not_match_service")
} else if _, ok := err.(*models.BlockError); ok {
errMsg = ctx.Tr("download.err_package_blocked", err.Error())
}
ctx.RenderWithErr(errMsg, "download", nil)
return
}
if err = models.IncreasePackageDownloadCount(importPath); err != nil {
ctx.Handle(500, "IncreasePackageDownloadCount", err)
return
} else if err = models.AddDownloader(ctx.RemoteAddr()); err != nil {
ctx.Handle(500, "AddDownloader", err)
return
}
ext := archive.GetExtension(importPath)
serveName := path.Base(importPath) + "-" + base.ShortSha(r.Revision) + ext
switch r.Storage {
case models.LOCAL:
ctx.ServeFile(path.Join(setting.ArchivePath, importPath, r.Revision+ext), serveName)
case models.QINIU:
ctx.Redirect("http://" + setting.BucketUrl + "/" + importPath + "-" + r.Revision + ext)
}
return
}
ctx.Data["pkgname"] = importPath
ctx.HTML(200, "download")
}
示例11: RunRule
func RunRule(ctx *middleware.Context) {
ctx.Data["PageIsBlocks"] = true
ctx.Data["PageIsBlocksRules"] = true
rid := ctx.ParamsInt64(":id")
count, keys, err := models.RunBlockRule(rid)
if err != nil {
ctx.Handle(500, "RunBlockRule", err)
return
}
if setting.ProdMode {
for _, k := range keys {
log.Trace("Deleting archive: %s", k)
if err = qiniu.DeleteArchive(k); err != nil {
log.Error(4, "Fail to delete archive(%s): %v", k, err)
}
log.Info("Archive deleted: %s", k)
}
}
ctx.Flash.Success(fmt.Sprintf("%d packages are blocked by rule ID: %d.", count, rid))
ctx.Redirect("/admin/blocks/rules")
}
示例12: NotFound
func NotFound(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("status.page_not_found")
ctx.Handle(404, "home.NotFound", nil)
}