mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-17 05:42:09 +08:00
build fail fix - we dont use yaml request payload
This commit is contained in:
parent
e345810288
commit
a9ec53b0e3
@ -81,7 +81,6 @@ var (
|
|||||||
FormMultipart = formMultipartBinding{}
|
FormMultipart = formMultipartBinding{}
|
||||||
ProtoBuf = protobufBinding{}
|
ProtoBuf = protobufBinding{}
|
||||||
MsgPack = msgpackBinding{}
|
MsgPack = msgpackBinding{}
|
||||||
YAML = yamlBinding{}
|
|
||||||
Uri = uriBinding{}
|
Uri = uriBinding{}
|
||||||
Header = headerBinding{}
|
Header = headerBinding{}
|
||||||
TOML = tomlBinding{}
|
TOML = tomlBinding{}
|
||||||
@ -103,8 +102,6 @@ func Default(method, contentType string) Binding {
|
|||||||
return ProtoBuf
|
return ProtoBuf
|
||||||
case MIMEMSGPACK, MIMEMSGPACK2:
|
case MIMEMSGPACK, MIMEMSGPACK2:
|
||||||
return MsgPack
|
return MsgPack
|
||||||
case MIMEYAML:
|
|
||||||
return YAML
|
|
||||||
case MIMETOML:
|
case MIMETOML:
|
||||||
return TOML
|
return TOML
|
||||||
case MIMEMultipartPOSTForm:
|
case MIMEMultipartPOSTForm:
|
||||||
|
@ -163,9 +163,6 @@ func TestBindingDefault(t *testing.T) {
|
|||||||
assert.Equal(t, ProtoBuf, Default("POST", MIMEPROTOBUF))
|
assert.Equal(t, ProtoBuf, Default("POST", MIMEPROTOBUF))
|
||||||
assert.Equal(t, ProtoBuf, Default("PUT", MIMEPROTOBUF))
|
assert.Equal(t, ProtoBuf, Default("PUT", MIMEPROTOBUF))
|
||||||
|
|
||||||
assert.Equal(t, YAML, Default("POST", MIMEYAML))
|
|
||||||
assert.Equal(t, YAML, Default("PUT", MIMEYAML))
|
|
||||||
|
|
||||||
assert.Equal(t, TOML, Default("POST", MIMETOML))
|
assert.Equal(t, TOML, Default("POST", MIMETOML))
|
||||||
assert.Equal(t, TOML, Default("PUT", MIMETOML))
|
assert.Equal(t, TOML, Default("PUT", MIMETOML))
|
||||||
}
|
}
|
||||||
@ -471,27 +468,6 @@ func TestBindingTOMLFail(t *testing.T) {
|
|||||||
`foo=\n"bar"`, `bar="foo"`)
|
`foo=\n"bar"`, `bar="foo"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBindingYAML(t *testing.T) {
|
|
||||||
testBodyBinding(t,
|
|
||||||
YAML, "yaml",
|
|
||||||
"/", "/",
|
|
||||||
`foo: bar`, `bar: foo`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBindingYAMLStringMap(t *testing.T) {
|
|
||||||
// YAML is a superset of JSON, so the test below is JSON (to avoid newlines)
|
|
||||||
testBodyBindingStringMap(t, YAML,
|
|
||||||
"/", "/",
|
|
||||||
`{"foo": "bar", "hello": "world"}`, `{"nested": {"foo": "bar"}}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBindingYAMLFail(t *testing.T) {
|
|
||||||
testBodyBindingFail(t,
|
|
||||||
YAML, "yaml",
|
|
||||||
"/", "/",
|
|
||||||
`foo:\nbar`, `bar: foo`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func createFormPostRequest(t *testing.T) *http.Request {
|
func createFormPostRequest(t *testing.T) *http.Request {
|
||||||
req, err := http.NewRequest("POST", "/?foo=getfoo&bar=getbar", bytes.NewBufferString("foo=bar&bar=foo"))
|
req, err := http.NewRequest("POST", "/?foo=getfoo&bar=getbar", bytes.NewBufferString("foo=bar&bar=foo"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
10
context.go
10
context.go
@ -632,11 +632,6 @@ func (c *Context) BindQuery(obj any) error {
|
|||||||
return c.MustBindWith(obj, binding.Query)
|
return c.MustBindWith(obj, binding.Query)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BindYAML is a shortcut for c.MustBindWith(obj, binding.YAML).
|
|
||||||
func (c *Context) BindYAML(obj any) error {
|
|
||||||
return c.MustBindWith(obj, binding.YAML)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BindTOML is a shortcut for c.MustBindWith(obj, binding.TOML).
|
// BindTOML is a shortcut for c.MustBindWith(obj, binding.TOML).
|
||||||
func (c *Context) BindTOML(obj interface{}) error {
|
func (c *Context) BindTOML(obj interface{}) error {
|
||||||
return c.MustBindWith(obj, binding.TOML)
|
return c.MustBindWith(obj, binding.TOML)
|
||||||
@ -695,11 +690,6 @@ func (c *Context) ShouldBindQuery(obj any) error {
|
|||||||
return c.ShouldBindWith(obj, binding.Query)
|
return c.ShouldBindWith(obj, binding.Query)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShouldBindYAML is a shortcut for c.ShouldBindWith(obj, binding.YAML).
|
|
||||||
func (c *Context) ShouldBindYAML(obj any) error {
|
|
||||||
return c.ShouldBindWith(obj, binding.YAML)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShouldBindTOML is a shortcut for c.ShouldBindWith(obj, binding.TOML).
|
// ShouldBindTOML is a shortcut for c.ShouldBindWith(obj, binding.TOML).
|
||||||
func (c *Context) ShouldBindTOML(obj interface{}) error {
|
func (c *Context) ShouldBindTOML(obj interface{}) error {
|
||||||
return c.ShouldBindWith(obj, binding.TOML)
|
return c.ShouldBindWith(obj, binding.TOML)
|
||||||
|
@ -1666,23 +1666,6 @@ func TestContextBindWithQuery(t *testing.T) {
|
|||||||
assert.Equal(t, 0, w.Body.Len())
|
assert.Equal(t, 0, w.Body.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContextBindWithYAML(t *testing.T) {
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
c, _ := CreateTestContext(w)
|
|
||||||
|
|
||||||
c.Request, _ = http.NewRequest("POST", "/", bytes.NewBufferString("foo: bar\nbar: foo"))
|
|
||||||
c.Request.Header.Add("Content-Type", MIMEXML) // set fake content-type
|
|
||||||
|
|
||||||
var obj struct {
|
|
||||||
Foo string `yaml:"foo"`
|
|
||||||
Bar string `yaml:"bar"`
|
|
||||||
}
|
|
||||||
assert.NoError(t, c.BindYAML(&obj))
|
|
||||||
assert.Equal(t, "foo", obj.Bar)
|
|
||||||
assert.Equal(t, "bar", obj.Foo)
|
|
||||||
assert.Equal(t, 0, w.Body.Len())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestContextBindWithTOML(t *testing.T) {
|
func TestContextBindWithTOML(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
c, _ := CreateTestContext(w)
|
c, _ := CreateTestContext(w)
|
||||||
@ -1816,23 +1799,6 @@ func TestContextShouldBindWithQuery(t *testing.T) {
|
|||||||
assert.Equal(t, 0, w.Body.Len())
|
assert.Equal(t, 0, w.Body.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContextShouldBindWithYAML(t *testing.T) {
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
c, _ := CreateTestContext(w)
|
|
||||||
|
|
||||||
c.Request, _ = http.NewRequest("POST", "/", bytes.NewBufferString("foo: bar\nbar: foo"))
|
|
||||||
c.Request.Header.Add("Content-Type", MIMEXML) // set fake content-type
|
|
||||||
|
|
||||||
var obj struct {
|
|
||||||
Foo string `yaml:"foo"`
|
|
||||||
Bar string `yaml:"bar"`
|
|
||||||
}
|
|
||||||
assert.NoError(t, c.ShouldBindYAML(&obj))
|
|
||||||
assert.Equal(t, "foo", obj.Bar)
|
|
||||||
assert.Equal(t, "bar", obj.Foo)
|
|
||||||
assert.Equal(t, 0, w.Body.Len())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestContextShouldBindWithTOML(t *testing.T) {
|
func TestContextShouldBindWithTOML(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
c, _ := CreateTestContext(w)
|
c, _ := CreateTestContext(w)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user