Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

added the ability to retreive form, body parameters, via c.Param and c.Params #1227

Merged
merged 4 commits into from
Aug 18, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ func (a *App) newContext(info RouteInfo, res http.ResponseWriter, req *http.Requ
params.Set(k, v)
}

if err := req.ParseForm(); err == nil {
for k, v := range req.Form {
for _, vv := range v {
params.Set(k, vv)
}
}
}

session := a.getSession(req, res)

ct := httpx.ContentType(req)
Expand Down
19 changes: 19 additions & 0 deletions default_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ func Test_DefaultContext_Param(t *testing.T) {
r.Equal("Mark", c.Param("name"))
}

func Test_DefaultContext_Param_form(t *testing.T) {
r := require.New(t)

app := New(Options{})
var name string
app.POST("/", func(c Context) error {
name = c.Param("name")
return nil
})

w := willie.New(app)
res := w.HTML("/").Post(map[string]string{
"name": "Mark",
})

r.Equal(200, res.Code)
r.Equal("Mark", name)
}

func Test_DefaultContext_GetSet(t *testing.T) {
r := require.New(t)
c := basicContext()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ require (
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
gopkg.in/mail.v2 v2.0.0-20180731213649-a0242b2233b4
)
)
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,4 @@ gopkg.in/russross/blackfriday.v1 v1.5.1/go.mod h1:NAEMj3mL3YDCD1Mxuzav3y8y68EZs2
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=