• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang middleware.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: 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")
}
开发者ID:harryyeh,项目名称:switch,代码行数:45,代码来源:download.go


示例17: ListLargeRevisions

func ListLargeRevisions(ctx *middleware.Context) {
	revs, err := models.GetLocalRevisions()
	if err != nil {
		ctx.JSON(500, map[string]string{
			"error": fmt.Sprintf("fail to get local revisions: %v", err),
		})
		return
	}

	largeRevs := make([]*ApiRevesion, 0, len(revs)/2)
	for _, rev := range revs {
		pkg, err := models.GetPakcageById(rev.PkgId)
		if err != nil {
			ctx.JSON(500, map[string]string{
				"error": fmt.Sprintf("fail to get package by ID(%d): %v", rev.PkgId, err),
			})
			return
		}

		ext := archive.GetExtension(pkg.ImportPath)
		localPath := path.Join(pkg.ImportPath, rev.Revision)
		fpath := path.Join(setting.ArchivePath, localPath+ext)

		if !com.IsFile(fpath) {
			continue
		}

		// Check archive size.
		f, err := os.Open(fpath)
		if err != nil {
			ctx.JSON(500, map[string]string{
				"error": fmt.Sprintf("fail to open file(%s): %v", fpath, err),
			})
			return
		}
		fi, err := f.Stat()
		if err != nil {
			ctx.JSON(500, map[string]string{
				"error": fmt.Sprintf("fail to get file info(%s): %v", fpath, err),
			})
			return
		}
		// Greater then MAX_UPLOAD_SIZE.
		if fi.Size() > setting.MaxUploadSize<<20 {
			largeRevs = append(largeRevs, &ApiRevesion{
				Id: rev.Id,
				Package: &ApiPackage{
					Id:         pkg.Id,
					ImportPath: pkg.ImportPath,
					Created:    pkg.Created,
				},
				Revision: rev.Revision,
				Size:     fi.Size(),
				Updated:  rev.Updated,
			})
			continue
		}
	}

	ctx.JSON(200, map[string]interface{}{
		"revisions": &largeRevs,
	})
}
开发者ID:harryyeh,项目名称:switch,代码行数:63,代码来源:package.go


示例18: BlockPackage

func BlockPackage(ctx *middleware.Context) {
	ctx.Data["PageIsBlocks"] = true
	ctx.Data["PageIsBlocksList"] = true
	ctx.HTML(200, "blocks/new")
}
开发者ID:harryyeh,项目名称:switch,代码行数:5,代码来源:block.go


示例19: NotFound

func NotFound(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("status.page_not_found")
	ctx.Handle(404, "home.NotFound", nil)
}
开发者ID:harryyeh,项目名称:switch,代码行数:4,代码来源:home.go


示例20: About

func About(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Locale.Tr("about_lower")
	ctx.Data["PageIsAbout"] = true
	ctx.HTML(200, "about")
}
开发者ID:harryyeh,项目名称:switch,代码行数:5,代码来源:home.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang dtos.DataSource类代码示例发布时间:2022-05-23
下一篇:
Golang log.Info函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap