本文整理汇总了Golang中github.com/labstack/echo.Context.FormValue方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.FormValue方法的具体用法?Golang Context.FormValue怎么用?Golang Context.FormValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/labstack/echo.Context
的用法示例。
在下文中一共展示了Context.FormValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: login
func login(c echo.Context) error {
username := c.FormValue("username")
password := c.FormValue("password")
if username == "jon" && password == "shhh!" {
// Create token
token := jwt.New(jwt.SigningMethodHS256)
// Set claims
claims := token.Claims.(jwt.MapClaims)
claims["name"] = "Jon Snow"
claims["admin"] = true
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
// Generate encoded token and send it as response.
t, err := token.SignedString([]byte("secret"))
if err != nil {
return err
}
return c.JSON(http.StatusOK, map[string]string{
"token": t,
})
}
return echo.ErrUnauthorized
}
示例2: Del
func (RuleController) Del(ctx echo.Context) error {
err := logic.DefaultRule.Delete(ctx, ctx.FormValue("id"))
if err != nil {
return fail(ctx, 1, "删除失败")
}
return success(ctx, nil)
}
示例3: 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)
}
示例4: 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())
}
示例5: upload
func upload(c echo.Context) error {
// Read form fields
name := c.FormValue("name")
email := c.FormValue("email")
//-----------
// Read file
//-----------
// Source
file, err := c.FormFile("file")
if err != nil {
return err
}
src, err := file.Open()
if err != nil {
return err
}
defer src.Close()
// Destination
dst, err := os.Create(file.Filename)
if err != nil {
return err
}
defer dst.Close()
// Copy
if _, err = io.Copy(dst, src); err != nil {
return err
}
return c.HTML(http.StatusOK, fmt.Sprintf("<p>File %s uploaded successfully with fields name=%s and email=%s.</p>", file.Filename, name, email))
}
示例6: Delete
// 删除消息
func (MessageController) Delete(ctx echo.Context) error {
id := ctx.FormValue("id")
msgtype := ctx.FormValue("msgtype")
if !logic.DefaultMessage.DeleteMessage(ctx, id, msgtype) {
return fail(ctx, 1, "对不起,删除失败,请稍候再试!")
}
return success(ctx, nil)
}
示例7: parseConds
func parseConds(ctx echo.Context, fields []string) map[string]string {
conds := make(map[string]string)
for _, field := range fields {
if value := ctx.FormValue(field); value != "" {
conds[field] = value
}
}
return conds
}
示例8: ChangePwd
// ChangePwd 修改密码
func (AccountController) ChangePwd(ctx echo.Context) error {
curUser := ctx.Get("user").(*model.Me)
curPasswd := ctx.FormValue("cur_passwd")
newPasswd := ctx.FormValue("passwd")
errMsg, err := logic.DefaultUser.UpdatePasswd(ctx, curUser.Username, curPasswd, newPasswd)
if err != nil {
return fail(ctx, 1, errMsg)
}
return success(ctx, nil)
}
示例9: EditHandlerPost
func EditHandlerPost(c echo.Context) error {
filepath := c.P(0)
eolIndex, _ := strconv.Atoi(c.FormValue("eol"))
content := c.FormValue("content")
convertedContent, err := eol.LineEnding(eolIndex).Apply(content)
if err != nil {
convertedContent = content
log.Println("Error while converting EOL. Saving without conversion.")
}
ioutil.WriteFile(filepath, []byte(convertedContent), 0644)
c.Set("editorView", NewEditorView(filepath, content))
return EditHandler(c)
}
示例10: Transfer
// Transfer 转换图片:通过 url 从远程下载图片然后转存到七牛
func (ImageController) Transfer(ctx echo.Context) error {
origUrl := ctx.FormValue("url")
if origUrl == "" {
return fail(ctx, 1, "url不能为空!")
}
path, err := logic.DefaultUploader.TransferUrl(ctx, origUrl)
if err != nil {
return fail(ctx, 2, "文件上传失败!")
}
return success(ctx, map[string]interface{}{"uri": logic.ImageDomain + path})
}
示例11: 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)
}
示例12: 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)
}
示例13: 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)
}
示例14: 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)
}
示例15: ChangeAvatar
// ChangeAvatar 更换头像
func (AccountController) ChangeAvatar(ctx echo.Context) error {
objLog := getLogger(ctx)
curUser := ctx.Get("user").(*model.Me)
// avatar 为空时,表示使用 gravater 头像
avatar := ctx.FormValue("avatar")
err := logic.DefaultUser.ChangeAvatar(ctx, curUser.Uid, avatar)
if err != nil {
objLog.Errorln("account controller change avatar error:", err)
return fail(ctx, 2, "更换头像失败")
}
return success(ctx, nil)
}