Skip to content
Myr

Renames new API for query/postform and params.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Manu Mtz-Almeida · committed by Manu Mtz-Almeida · parent 40d41bb · Browse files · 3 files+23 added−34 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+23 added−34 removed

  • other:+23 added−34 removed

3 files+23 added−34 removed

modified:context_test.go+10 added-5 removed
137 unmodified lines
138 c.Request.Header.Add("Content-Type", MIMEPOSTForm)139140 assert.Equal(t, c.DefaultPostFormValue("foo", "none"), "bar")141 assert.Equal(t, c.PostFormValue("foo"), "bar")142 assert.Equal(t, c.FormValue("foo"), "bar")142 assert.Empty(t, c.FormValue("foo"))143144 assert.Equal(t, c.DefaultPostFormValue("page", "0"), "11")145 assert.Equal(t, c.PostFormValue("page"), "11")146 assert.Equal(t, c.FormValue("page"), "11")144 assert.Equal(t, c.DefaultPostForm("page", "0"), "11")145 assert.Equal(t, c.PostForm("page"), "11")146 assert.Equal(t, c.InputQuery("page"), "")147148 assert.Equal(t, c.PostFormValue("both"), "POST")149 assert.Equal(t, c.FormValue("both"), "POST")149 assert.Equal(t, c.FormValue("both"), "GET")150151 assert.Equal(t, c.FormValue("id"), "main")152 assert.Empty(t, c.PostFormValue("id"))153154 assert.Equal(t, c.DefaultPostFormValue("NoKey", "nada"), "nada")155 assert.Empty(t, c.PostFormValue("NoKey"))156 assert.Empty(t, c.FormValue("NoKey"))157158 c.Param("page")159 c.Query("page")160 c.PostForm("page")161162}163164// Tests that the response is serialized as JSON165// and Content-Type is set to application/json
329 unmodified lines
modified:context.go+13 added-25 removed
189 unmodified lines
190/************ INPUT DATA ************/191/************************************/192193/** Shortcut for c.Request.FormValue(key) */194func (c *Context) FormValue(key string) (va string) {195 va, _ = c.formValue(key)194func (c *Context) Query(key string) (va string) {195 va, _ = c.query(key)196 return197}198199/** Shortcut for c.Request.PostFormValue(key) */200func (c *Context) PostFormValue(key string) (va string) {201 va, _ = c.postFormValue(key)200func (c *Context) PostForm(key string) (va string) {201 va, _ = c.postForm(key)202 return203}204205/** Shortcut for c.Params.ByName(key) */206func (c *Context) ParamValue(key string) (va string) {207 va, _ = c.paramValue(key)206func (c *Context) Param(key string) (va string) {207 va, _ = c.Params.Get(key)208 return209}210211func (c *Context) DefaultPostFormValue(key, defaultValue string) string {212 if va, ok := c.postFormValue(key); ok {211func (c *Context) DefaultPostForm(key, defaultValue string) string {212 if va, ok := c.postForm(key); ok {213 return va214 }215 return defaultValue216}217218func (c *Context) DefaultFormValue(key, defaultValue string) string {219 if va, ok := c.formValue(key); ok {218func (c *Context) DefaultQuery(key, defaultValue string) string {219 if va, ok := c.query(key); ok {220 return va221 }222 return defaultValue223}224225func (c *Context) DefaultParamValue(key, defaultValue string) string {226 if va, ok := c.paramValue(key); ok {227 return va228 }229 return defaultValue230}231232func (c *Context) paramValue(key string) (string, bool) {233 return c.Params.Get(key)234}235236func (c *Context) formValue(key string) (string, bool) {225func (c *Context) query(key string) (string, bool) {226 req := c.Request238 req.ParseForm()239 if values, ok := req.Form[key]; ok && len(values) > 0 {227 if values, ok := req.URL.Query()[key]; ok && len(values) > 0 {228 return values[0], true229 }230 return "", false231}232245func (c *Context) postFormValue(key string) (string, bool) {233func (c *Context) postForm(key string) (string, bool) {234 req := c.Request235 req.ParseForm()236 if values, ok := req.PostForm[key]; ok && len(values) > 0 {237 return values[0], true
224 unmodified lines
modified:routes_test.go-4 removed
126 unmodified lines
127 wild = c.Params.ByName("wild")128129 assert.Equal(t, name, c.ParamValue("name"))130 assert.Equal(t, lastName, c.ParamValue("last_name"))131132 assert.Equal(t, name, c.DefaultParamValue("name", "nothing"))133 assert.Equal(t, lastName, c.DefaultParamValue("last_name", "nothing"))134 assert.Equal(t, c.DefaultParamValue("noKey", "default"), "default")131 })132133 w := performRequest(router, "GET", "/test/john/smith/is/super/great")134
148 unmodified lines