本书未发布

12.13. Form

未匹配的标注
package main

/*
Form相关方法定义。
type Context interface {
    FormValue(string) string
    FormValues() map[string][]string
    FormFile(string) *multipart.FileHeader
    FormFiles() map[string][]*multipart.FileHeader
    ...
}
*/

import (
    "fmt"
    "github.com/eudore/eudore"
    "github.com/eudore/eudore/component/httptest"
)

func main() {
    app := eudore.NewApp()
    app.AnyFunc("/*path", func(ctx eudore.Context) {
        ctx.FormValue("haha")
        ctx.FormValue("name")
        ctx.FormFile("haha")
        ctx.FormFile("file")
        for key, val := range ctx.FormValues() {
            fmt.Println(key, val)
        }

        for key, file := range ctx.FormFiles() {
            fmt.Println(key, file[0].Filename)
        }
    })

    client := httptest.NewClient(app)
    client.NewRequest("POST", "/").WithBodyFormValue("name", "my name").WithBodyFormValue("message", "msg").WithBodyFormFile("file", "contextBindForm.go", "contextBindForm file content").Do()
    client.NewRequest("POST", "/").WithBodyJSONValue("name", "my name").WithBodyJSONValue("message", "msg").Do()

    app.Listen(":8088")
    // app.CancelFunc()
    app.Run()
}

反馈和交流请加群组:QQ群373278915

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
讨论数量: 0
发起讨论 只看当前版本


暂无话题~