本书未发布
12.18. 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。