本文整理匯總了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)
}