本文整理匯總了Golang中github.com/gpmgo/switch/modules/middleware.Context.Query方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Query方法的具體用法?Golang Context.Query怎麽用?Golang Context.Query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gpmgo/switch/modules/middleware.Context
的用法示例。
在下文中一共展示了Context.Query方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: Download
func Download(ctx *middleware.Context) {
importPath := archive.GetRootPath(ctx.Query("pkgname"))
rev := ctx.Query("revision")
r, err := models.CheckPkg(importPath, rev)
if err != nil {
ctx.JSON(422, map[string]interface{}{
"error": err.Error(),
})
return
}
if err = models.IncreasePackageDownloadCount(importPath); err != nil {
ctx.JSON(500, map[string]interface{}{
"error": err.Error(),
})
return
} else if err = models.AddDownloader(ctx.RemoteAddr()); err != nil {
ctx.JSON(500, map[string]interface{}{
"error": err.Error(),
})
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)
}
}
示例3: 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")
}
示例4: BlockPackage
func BlockPackage(ctx *middleware.Context) {
id := ctx.QueryInt64("id")
pkg, err := models.GetPakcageById(id)
if err != nil {
if err == models.ErrPackageNotExist {
ctx.JSON(404, map[string]string{
"error": err.Error(),
})
} else {
ctx.JSON(500, map[string]string{
"error": fmt.Sprintf("fail to get package by ID(%d): %v", id, err),
})
}
return
}
revs, err := pkg.GetRevisions()
if err != nil {
ctx.JSON(500, map[string]string{
"error": fmt.Sprintf("fail to get package revisions by ID(%d): %v", id, err),
})
return
}
// Delete package archives.
ext := archive.GetExtension(pkg.ImportPath)
for _, rev := range revs {
switch rev.Storage {
case models.QINIU:
key := pkg.ImportPath + "-" + rev.Revision + ext
if err = qiniu.DeleteArchive(key); err != nil {
ctx.JSON(500, map[string]string{
"error": fmt.Sprintf("fail to delete archive(%s): %v", key, err),
})
return
}
}
}
os.RemoveAll(path.Join(setting.ArchivePath, pkg.ImportPath))
if err = models.BlockPackage(pkg, revs, ctx.Query("note")); err != nil {
ctx.JSON(500, map[string]string{
"error": fmt.Sprintf("fail to block package by ID(%d): %v", id, err),
})
return
}
ctx.JSON(200, map[string]interface{}{
"ok": true,
})
}
示例5: 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,
})
}
示例6: 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")
}
示例7: 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")
}
示例8: AuthPost
func AuthPost(ctx *middleware.Context) {
ctx.SetCookie("access_token", ctx.Query("token"))
ctx.Redirect("/admin")
}