当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Redirect方法代码示例

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


在下文中一共展示了Context.Redirect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: specialHandles

func specialHandles(ctx *middleware.Context, pinfo *models.PkgInfo) bool {
	// Only show imports.
	if strings.HasSuffix(ctx.Req.RequestURI, "?imports") {
		ctx.Data["Packages"] = models.GetPkgInfosByPaths(strings.Split(pinfo.ImportPaths, "|"))
		ctx.HTML(200, DOCS_IMPORTS)
		return true
	}

	// Refresh documentation.
	if strings.HasSuffix(ctx.Req.RequestURI, "?refresh") {
		if !pinfo.CanRefresh() {
			ctx.Flash.Info(ctx.Tr("docs.refresh.too_often"))
		} else {
			importPath := ctx.Params("*")
			_, err := doc.CheckPackage(importPath, ctx.Render, doc.REQUEST_TYPE_REFRESH)
			if err != nil {
				handleError(ctx, err)
				return true
			}
		}
		ctx.Redirect(ctx.Data["Link"].(string))
		return true
	}

	return false
}
开发者ID:qiancy,项目名称:gowalker,代码行数:26,代码来源:docs.go

示例2: Search

func Search(ctx *middleware.Context) {
	q := ctx.Query("q")

	if ctx.Query("auto_redirect") == "true" &&
		(base.IsGoRepoPath(q) || base.IsGAERepoPath(q) ||
			base.IsValidRemotePath(q)) {
		ctx.Redirect("/" + q)
		return
	}

	var (
		results []*models.PkgInfo
		err     error
	)
	switch q {
	case "gorepos":
		results, err = models.GetGoRepos()
	case "gosubrepos":
		results, err = models.GetGoSubepos()
	case "gaesdk":
		results, err = models.GetGAERepos()
	default:
		results, err = models.SearchPkgInfo(100, q)
	}
	if err != nil {
		ctx.Flash.Error(err.Error(), true)
	} else {
		ctx.Data["Results"] = results
	}

	ctx.Data["Keyword"] = q
	ctx.HTML(200, SEARCH)
}
开发者ID:jmptrader,项目名称:gowalker,代码行数:33,代码来源:search.go

示例3: handleError

func handleError(ctx *middleware.Context, err error) {
	importPath := ctx.Params("*")
	if err == doc.ErrInvalidRemotePath {
		ctx.Redirect("/search?q=" + importPath)
		return
	}
	ctx.Flash.Error(importPath+": "+err.Error(), true)
	ctx.Flash.Info(ctx.Tr("form.click_to_search", importPath), true)
	Home(ctx)
}
开发者ID:qiancy,项目名称:gowalker,代码行数:10,代码来源:docs.go

示例4: handleError

func handleError(ctx *middleware.Context, err error) {
	importPath := ctx.Params("*")
	if err == doc.ErrInvalidRemotePath {
		ctx.Redirect("/search?q=" + importPath)
		return
	}
	ctx.Flash.Error(importPath+": "+strings.Replace(err.Error(), setting.GitHubCredentials, "<GitHubCredentials>", -1), true)
	ctx.Flash.Info(ctx.Tr("form.click_to_search", importPath), true)
	Home(ctx)
}
开发者ID:ewindfall,项目名称:gowalker,代码行数:10,代码来源:docs.go

示例5: handleError

func handleError(ctx *middleware.Context, err error) {
	importPath := ctx.Params("*")
	if err == doc.ErrInvalidRemotePath {
		ctx.Redirect("/search?q=" + importPath)
		return
	}

	if strings.Contains(err.Error(), "<meta> not found") ||
		strings.Contains(err.Error(), "resource not found") {
		models.DeletePackageByPath(importPath)
	}

	ctx.Flash.Error(importPath+": "+strings.Replace(err.Error(), setting.GitHubCredentials, "<GitHubCredentials>", -1), true)
	ctx.Flash.Info(ctx.Tr("form.click_to_search", importPath), true)
	Home(ctx)
}
开发者ID:imjerrybao,项目名称:gowalker,代码行数:16,代码来源:docs.go

示例6: Search

func Search(ctx *middleware.Context) {
	q := ctx.Query("q")

	if ctx.Query("auto_redirect") == "true" &&
		(base.IsGoRepoPath(q) || base.IsValidRemotePath(q)) {
		ctx.Redirect("/" + q)
		return
	}

	results, err := models.SearchPkgInfo(100, q)
	if err != nil {
		ctx.Flash.Error(err.Error(), true)
	} else {
		ctx.Data["Results"] = results
	}

	ctx.Data["Keyword"] = q
	ctx.HTML(200, SEARCH)
}
开发者ID:xushiwei,项目名称:gowalker,代码行数:19,代码来源:search.go

示例7: Docs

func Docs(ctx *middleware.Context) {
	importPath := ctx.Params("*")

	if base.IsGAERepoPath(importPath) {
		ctx.Redirect("/google.golang.org/" + importPath)
		return
	}

	pinfo, err := doc.CheckPackage(importPath, ctx.Render, doc.REQUEST_TYPE_HUMAN)
	if err != nil {
		handleError(ctx, err)
		return
	}

	ctx.Data["PageIsDocs"] = true
	ctx.Data["Title"] = pinfo.ImportPath
	ctx.Data["ParentPath"] = path.Dir(pinfo.ImportPath)
	ctx.Data["ProjectName"] = path.Base(pinfo.ImportPath)
	ctx.Data["ProjectPath"] = pinfo.ProjectPath

	if specialHandles(ctx, pinfo) {
		return
	}

	if pinfo.IsGoRepo {
		ctx.Flash.Info(ctx.Tr("docs.turn_into_search", importPath), true)
	}

	ctx.Data["PkgDesc"] = pinfo.Synopsis

	// README.
	lang := ctx.Data["Lang"].(string)[:2]
	readmePath := setting.DocsJsPath + pinfo.ImportPath + "_RM_" + lang + ".js"
	if com.IsFile(readmePath) {
		ctx.Data["IsHasReadme"] = true
		ctx.Data["ReadmePath"] = readmePath
	} else {
		readmePath := setting.DocsJsPath + pinfo.ImportPath + "_RM_en.js"
		if com.IsFile(readmePath) {
			ctx.Data["IsHasReadme"] = true
			ctx.Data["ReadmePath"] = readmePath
		}
	}

	// Documentation.
	docJS := make([]string, 0, pinfo.JsNum+1)
	docJS = append(docJS, setting.DocsJsPath+importPath+".js")
	for i := 1; i <= pinfo.JsNum; i++ {
		docJS = append(docJS, fmt.Sprintf("%s%s-%d.js", setting.DocsJsPath, importPath, i))
	}
	ctx.Data["DocJS"] = docJS
	ctx.Data["Timestamp"] = pinfo.Created
	if time.Now().UTC().Add(-5*time.Second).Unix() < pinfo.Created {
		ctx.Flash.Success(ctx.Tr("docs.generate_success"), true)
	}

	// Subdirs.
	if len(pinfo.Subdirs) > 0 {
		ctx.Data["IsHasSubdirs"] = true
		ctx.Data["ViewDirPath"] = pinfo.ViewDirPath
		ctx.Data["Subdirs"] = models.GetSubPkgs(pinfo.ImportPath, strings.Split(pinfo.Subdirs, "|"))
	}

	// Imports and references.
	ctx.Data["ImportNum"] = pinfo.ImportNum
	ctx.Data["RefNum"] = pinfo.RefNum

	// Tools.
	ctx.Data["TimeDuration"] = base.TimeSince(time.Unix(pinfo.Created, 0), ctx.Locale.Language())
	ctx.Data["CanRefresh"] = pinfo.CanRefresh()

	updateHistory(ctx, pinfo.ID)

	ctx.HTML(200, DOCS)
}
开发者ID:ewindfall,项目名称:gowalker,代码行数:75,代码来源:docs.go

示例8: Badge

func Badge(ctx *middleware.Context) {
	ctx.Redirect("https://img.shields.io/badge/Go%20Walker-API%20Documentation-green.svg?style=flat-square")
}
开发者ID:qiancy,项目名称:gowalker,代码行数:3,代码来源:api.go


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