當前位置: 首頁>>代碼示例>>Golang>>正文


Golang middleware.Context類代碼示例

本文整理匯總了Golang中github.com/gpmgo/switch/modules/middleware.Context的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Context類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:27,代碼來源:block.go

示例2: Auth

func Auth(ctx *middleware.Context) {
	if len(setting.AccessToken) == 0 ||
		ctx.GetCookie("access_token") != setting.AccessToken {
		ctx.Data["PageIsAuth"] = true
		ctx.HTML(200, "auth")
	}
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:7,代碼來源:auth.go

示例3: LargeRevisions

func LargeRevisions(ctx *middleware.Context) {
	ctx.Data["PageIsPackages"] = true
	ctx.Data["PageIsPackagesLarges"] = true

	models.GetLocalRevisions()

	ctx.HTML(200, "packages/larges")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:8,代碼來源:package.go

示例4: 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")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:13,代碼來源:block.go

示例5: 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")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:13,代碼來源:block.go

示例6: 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")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:12,代碼來源:home.go

示例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))
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:13,代碼來源:package.go

示例8: GetRevision

func GetRevision(ctx *middleware.Context) {
	importPath := archive.GetRootPath(ctx.Query("pkgname"))
	rev := ctx.Query("revision")
	n := archive.NewNode(importPath, rev)
	if err := n.GetRevision(); err != nil {
		ctx.JSON(422, map[string]interface{}{
			"error": err.Error(),
		})
		return
	}
	ctx.JSON(200, map[string]interface{}{
		"sha": n.Revision,
	})
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:14,代碼來源:package.go

示例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")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:16,代碼來源:package.go

示例10: 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")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:12,代碼來源:block.go

示例11: 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")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:12,代碼來源:block.go

示例12: 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")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:16,代碼來源:block.go

示例13: 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")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:24,代碼來源:block.go

示例14: AuthPost

func AuthPost(ctx *middleware.Context) {
	ctx.SetCookie("access_token", ctx.Query("token"))
	ctx.Redirect("/admin")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:4,代碼來源:auth.go

示例15: NewBlockRule

func NewBlockRule(ctx *middleware.Context) {
	ctx.Data["PageIsBlocks"] = true
	ctx.Data["PageIsBlocksRules"] = true
	ctx.HTML(200, "blocks/rules_new")
}
開發者ID:harryyeh,項目名稱:switch,代碼行數:5,代碼來源:block.go


注:本文中的github.com/gpmgo/switch/modules/middleware.Context類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。