本文整理汇总了Golang中github.com/labstack/echo.Context.FormParams方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.FormParams方法的具体用法?Golang Context.FormParams怎么用?Golang Context.FormParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/labstack/echo.Context
的用法示例。
在下文中一共展示了Context.FormParams方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Create
// Create 发布新资源
func (ResourceController) Create(ctx echo.Context) error {
title := ctx.FormValue("title")
// 请求新建资源页面
if title == "" || ctx.Request().Method() != "POST" {
return render(ctx, "resources/new.html", map[string]interface{}{"activeResources": "active", "categories": logic.AllCategory})
}
errMsg := ""
resForm := ctx.FormValue("form")
if resForm == model.LinkForm {
if ctx.FormValue("url") == "" {
errMsg = "url不能为空"
}
} else {
if ctx.FormValue("content") == "" {
errMsg = "内容不能为空"
}
}
if errMsg != "" {
return fail(ctx, 1, errMsg)
}
me := ctx.Get("user").(*model.Me)
err := logic.DefaultResource.Publish(ctx, me, ctx.FormParams())
if err != nil {
return fail(ctx, 2, "内部服务错误,请稍候再试!")
}
return success(ctx, nil)
}
示例2: Modify
// Modify 修改主题
func (TopicController) Modify(ctx echo.Context) error {
tid := goutils.MustInt(ctx.FormValue("tid"))
if tid == 0 {
return ctx.Redirect(http.StatusSeeOther, "/topics")
}
nodes := logic.GenNodes()
if ctx.Request().Method() != "POST" {
topics := logic.DefaultTopic.FindByTids([]int{tid})
if len(topics) == 0 {
return ctx.Redirect(http.StatusSeeOther, "/topics")
}
return render(ctx, "topics/new.html", map[string]interface{}{"nodes": nodes, "topic": topics[0], "activeTopics": "active"})
}
me := ctx.Get("user").(*model.Me)
err := logic.DefaultTopic.Publish(ctx, me, ctx.FormParams())
if err != nil {
if err == logic.NotModifyAuthorityErr {
return fail(ctx, 1, "没有权限操作")
}
return fail(ctx, 2, "服务错误,请稍后重试!")
}
return success(ctx, nil)
}
示例3: defaultCacheKeyAlgorithm
func defaultCacheKeyAlgorithm(ctx echo.Context) string {
filter := map[string]bool{
"from": true,
"sign": true,
"nonce": true,
"timestamp": true,
}
form := ctx.FormParams()
var keys = make([]string, 0, len(form))
for key := range form {
if _, ok := filter[key]; !ok {
keys = append(keys, key)
}
}
sort.Sort(sort.StringSlice(keys))
buffer := goutils.NewBuffer()
for _, k := range keys {
buffer.Append(k).Append("=").Append(ctx.FormValue(k))
}
req := ctx.Request()
return goutils.Md5(req.Method() + req.URL().Path() + buffer.String())
}
示例4: Create
// Create 评论(或回复)
func (CommentController) Create(ctx echo.Context) error {
user := ctx.Get("user").(*model.Me)
// 入库
objid := goutils.MustInt(ctx.Param("objid"))
comment, err := logic.DefaultComment.Publish(ctx, user.Uid, objid, ctx.FormParams())
if err != nil {
return fail(ctx, 1, "服务器内部错误")
}
return success(ctx, comment)
}
示例5: New
// New 新建规则
func (RuleController) New(ctx echo.Context) error {
var data = make(map[string]interface{})
if ctx.FormValue("submit") == "1" {
user := ctx.Get("user").(*model.Me)
errMsg, err := logic.DefaultRule.Save(ctx, ctx.FormParams(), user.Username)
if err != nil {
return fail(ctx, 1, errMsg)
}
return success(ctx, nil)
}
return render(ctx, "rule/new.html", data)
}
示例6: Create
// Create 创建wiki页
func (WikiController) Create(ctx echo.Context) error {
title := ctx.FormValue("title")
// 请求新建 wiki 页面
if title == "" || ctx.Request().Method() != "POST" {
return render(ctx, "wiki/new.html", map[string]interface{}{"activeWiki": "active"})
}
me := ctx.Get("user").(*model.Me)
err := logic.DefaultWiki.Create(ctx, me, ctx.FormParams())
if err != nil {
return fail(ctx, 1, "内部服务错误")
}
return success(ctx, nil)
}
示例7: Create
// Create 新建项目
func (ProjectController) Create(ctx echo.Context) error {
name := ctx.FormValue("name")
// 请求新建项目页面
if name == "" || ctx.Request().Method() != "POST" {
project := &model.OpenProject{}
return render(ctx, "projects/new.html", map[string]interface{}{"project": project, "activeProjects": "active"})
}
user := ctx.Get("user").(*model.Me)
err := logic.DefaultProject.Publish(ctx, user, ctx.FormParams())
if err != nil {
return fail(ctx, 1, "内部服务错误!")
}
return success(ctx, nil)
}
示例8: Create
// Create 新建主题
func (TopicController) Create(ctx echo.Context) error {
nodes := logic.GenNodes()
title := ctx.FormValue("title")
// 请求新建主题页面
if title == "" || ctx.Request().Method() != "POST" {
return render(ctx, "topics/new.html", map[string]interface{}{"nodes": nodes, "activeTopics": "active"})
}
me := ctx.Get("user").(*model.Me)
err := logic.DefaultTopic.Publish(ctx, me, ctx.FormParams())
if err != nil {
return fail(ctx, 1, "内部服务错误")
}
return success(ctx, nil)
}
示例9: Like
// Like 喜欢(或取消喜欢)
func (LikeController) Like(ctx echo.Context) error {
form := ctx.FormParams()
if !util.CheckInt(form, "objtype") || !util.CheckInt(form, "flag") {
return fail(ctx, 1, "参数错误")
}
user := ctx.Get("user").(*model.Me)
objid := goutils.MustInt(ctx.Param("objid"))
objtype := goutils.MustInt(ctx.FormValue("objtype"))
likeFlag := goutils.MustInt(ctx.FormValue("flag"))
err := logic.DefaultLike.LikeObject(ctx, user.Uid, objid, objtype, likeFlag)
if err != nil {
return fail(ctx, 2, "服务器内部错误")
}
return success(ctx, nil)
}
示例10: Modify
// Modify 编辑规则
func (self RuleController) Modify(ctx echo.Context) error {
var data = make(map[string]interface{})
if ctx.FormValue("submit") == "1" {
user := ctx.Get("user").(*model.Me)
errMsg, err := logic.DefaultRule.Save(ctx, ctx.FormParams(), user.Username)
if err != nil {
return fail(ctx, 1, errMsg)
}
return success(ctx, nil)
}
rule := logic.DefaultRule.FindById(ctx, ctx.QueryParam("id"))
if rule == nil {
return ctx.Redirect(http.StatusSeeOther, ctx.Echo().URI(echo.HandlerFunc(self.RuleList)))
}
data["rule"] = rule
return render(ctx, "rule/modify.html", data)
}
示例11: Publish
// Publish
func (ReadingController) Publish(ctx echo.Context) error {
var data = make(map[string]interface{})
if ctx.FormValue("submit") == "1" {
user := ctx.Get("user").(*model.Me)
errMsg, err := logic.DefaultReading.SaveReading(ctx, ctx.FormParams(), user.Username)
if err != nil {
return fail(ctx, 1, errMsg)
}
return success(ctx, nil)
}
id := goutils.MustInt(ctx.QueryParam("id"))
if id != 0 {
reading := logic.DefaultReading.FindById(ctx, id)
if reading != nil {
data["reading"] = reading
}
}
return render(ctx, "reading/modify.html", data)
}
示例12: Modify
// Modify 修改项目
func (ProjectController) Modify(ctx echo.Context) error {
id := goutils.MustInt(ctx.FormValue("id"))
if id == 0 {
return ctx.Redirect(http.StatusSeeOther, "/projects")
}
// 请求编辑项目页面
if ctx.Request().Method() != "POST" {
project := logic.DefaultProject.FindOne(ctx, id)
return render(ctx, "projects/new.html", map[string]interface{}{"project": project, "activeProjects": "active"})
}
user := ctx.Get("user").(*model.Me)
err := logic.DefaultProject.Publish(ctx, user, ctx.FormParams())
if err != nil {
if err == logic.NotModifyAuthorityErr {
return ctx.String(http.StatusForbidden, "没有权限")
}
return fail(ctx, 1, "内部服务错误!")
}
return success(ctx, nil)
}
示例13: Modify
// Modify 修改資源
func (ResourceController) Modify(ctx echo.Context) error {
id := goutils.MustInt(ctx.FormValue("id"))
if id == 0 {
return ctx.Redirect(http.StatusSeeOther, "/resources/cat/1")
}
// 请求编辑資源页面
if ctx.Request().Method() != "POST" {
resource := logic.DefaultResource.FindResource(ctx, id)
return render(ctx, "resources/new.html", map[string]interface{}{"resource": resource, "activeResources": "active", "categories": logic.AllCategory})
}
me := ctx.Get("user").(*model.Me)
err := logic.DefaultResource.Publish(ctx, me, ctx.FormParams())
if err != nil {
if err == logic.NotModifyAuthorityErr {
return ctx.String(http.StatusForbidden, "没有权限修改")
}
return fail(ctx, 2, "内部服务错误,请稍候再试!")
}
return success(ctx, nil)
}
示例14: Modify
// Modify
func (self ArticleController) Modify(ctx echo.Context) error {
var data = make(map[string]interface{})
if ctx.FormValue("submit") == "1" {
user := ctx.Get("user").(*model.Me)
errMsg, err := logic.DefaultArticle.Modify(ctx, user, ctx.FormParams())
if err != nil {
return fail(ctx, 1, errMsg)
}
return success(ctx, nil)
}
article, err := logic.DefaultArticle.FindById(ctx, ctx.QueryParam("id"))
if err != nil {
return ctx.Redirect(http.StatusSeeOther, ctx.Echo().URI(echo.HandlerFunc(self.ArticleList)))
}
data["article"] = article
data["statusSlice"] = model.ArticleStatusSlice
data["langSlice"] = model.LangSlice
return render(ctx, "article/modify.html", data)
}