mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 09:34:33 +08:00
Update to the latest
This commit is contained in:
parent
81843aad48
commit
d4fc70d260
@ -11,6 +11,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -690,6 +691,28 @@ func TestUriBinding(t *testing.T) {
|
|||||||
assert.Equal(t, map[string]interface{}(nil), not.Name)
|
assert.Equal(t, map[string]interface{}(nil), not.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUriInnerBinding(t *testing.T) {
|
||||||
|
type Tag struct {
|
||||||
|
Name string `uri:"name"`
|
||||||
|
S struct {
|
||||||
|
Age int `uri:"age"`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedName := "mike"
|
||||||
|
expectedAge := 25
|
||||||
|
|
||||||
|
m := map[string][]string{
|
||||||
|
"name": {expectedName},
|
||||||
|
"age": {strconv.Itoa(expectedAge)},
|
||||||
|
}
|
||||||
|
|
||||||
|
var tag Tag
|
||||||
|
assert.NoError(t, Uri.BindUri(m, &tag))
|
||||||
|
assert.Equal(t, tag.Name, expectedName)
|
||||||
|
assert.Equal(t, tag.S.Age, expectedAge)
|
||||||
|
}
|
||||||
|
|
||||||
func testFormBinding(t *testing.T, method, path, badPath, body, badBody string) {
|
func testFormBinding(t *testing.T, method, path, badPath, body, badBody string) {
|
||||||
b := Form
|
b := Form
|
||||||
assert.Equal(t, "form", b.Name())
|
assert.Equal(t, "form", b.Name())
|
||||||
|
@ -55,7 +55,7 @@ func mapFormByTag(ptr interface{}, form map[string][]string, tag string) error {
|
|||||||
structFieldKind = structField.Kind()
|
structFieldKind = structField.Kind()
|
||||||
}
|
}
|
||||||
if structFieldKind == reflect.Struct {
|
if structFieldKind == reflect.Struct {
|
||||||
err := mapForm(structField.Addr().Interface(), form)
|
err := mapFormByTag(structField.Addr().Interface(), form, tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1457,7 +1457,7 @@ func TestContextShouldBindWithXML(t *testing.T) {
|
|||||||
c.Request, _ = http.NewRequest("POST", "/", bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8"?>
|
c.Request, _ = http.NewRequest("POST", "/", bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<root>
|
<root>
|
||||||
<foo>FOO</foo>
|
<foo>FOO</foo>
|
||||||
<bar>BAR</bar>
|
<bar>BAR</bar>
|
||||||
</root>`))
|
</root>`))
|
||||||
c.Request.Header.Add("Content-Type", MIMEXML) // set fake content-type
|
c.Request.Header.Add("Content-Type", MIMEXML) // set fake content-type
|
||||||
|
|
||||||
@ -1475,15 +1475,19 @@ func TestContextShouldBindWithQuery(t *testing.T) {
|
|||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
c, _ := CreateTestContext(w)
|
c, _ := CreateTestContext(w)
|
||||||
|
|
||||||
c.Request, _ = http.NewRequest("POST", "/?foo=bar&bar=foo", bytes.NewBufferString("foo=unused"))
|
c.Request, _ = http.NewRequest("POST", "/?foo=bar&bar=foo&Foo=bar1&Bar=foo1", bytes.NewBufferString("foo=unused"))
|
||||||
|
|
||||||
var obj struct {
|
var obj struct {
|
||||||
Foo string `form:"foo"`
|
Foo string `form:"foo"`
|
||||||
Bar string `form:"bar"`
|
Bar string `form:"bar"`
|
||||||
|
Foo1 string `form:"Foo"`
|
||||||
|
Bar1 string `form:"Bar"`
|
||||||
}
|
}
|
||||||
assert.NoError(t, c.ShouldBindQuery(&obj))
|
assert.NoError(t, c.ShouldBindQuery(&obj))
|
||||||
assert.Equal(t, "foo", obj.Bar)
|
assert.Equal(t, "foo", obj.Bar)
|
||||||
assert.Equal(t, "bar", obj.Foo)
|
assert.Equal(t, "bar", obj.Foo)
|
||||||
|
assert.Equal(t, "foo1", obj.Bar1)
|
||||||
|
assert.Equal(t, "bar1", obj.Foo1)
|
||||||
assert.Equal(t, 0, w.Body.Len())
|
assert.Equal(t, 0, w.Body.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ func TestBadUnixSocket(t *testing.T) {
|
|||||||
func TestFileDescriptor(t *testing.T) {
|
func TestFileDescriptor(t *testing.T) {
|
||||||
router := New()
|
router := New()
|
||||||
|
|
||||||
addr, err := net.ResolveTCPAddr("tcp", ":8000")
|
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
listener, err := net.ListenTCP("tcp", addr)
|
listener, err := net.ListenTCP("tcp", addr)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -152,7 +152,7 @@ func TestFileDescriptor(t *testing.T) {
|
|||||||
// otherwise the main thread will complete
|
// otherwise the main thread will complete
|
||||||
time.Sleep(5 * time.Millisecond)
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
|
||||||
c, err := net.Dial("tcp", "localhost:8000")
|
c, err := net.Dial("tcp", listener.Addr().String())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")
|
fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")
|
||||||
|
@ -47,7 +47,7 @@ type RouterGroup struct {
|
|||||||
|
|
||||||
var _ IRouter = &RouterGroup{}
|
var _ IRouter = &RouterGroup{}
|
||||||
|
|
||||||
// Use adds middleware to the group, see example code in github.
|
// Use adds middleware to the group, see example code in GitHub.
|
||||||
func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes {
|
func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes {
|
||||||
group.Handlers = append(group.Handlers, middleware...)
|
group.Handlers = append(group.Handlers, middleware...)
|
||||||
return group.returnObj()
|
return group.returnObj()
|
||||||
@ -78,7 +78,7 @@ func (group *RouterGroup) handle(httpMethod, relativePath string, handlers Handl
|
|||||||
|
|
||||||
// Handle registers a new request handle and middleware with the given path and method.
|
// Handle registers a new request handle and middleware with the given path and method.
|
||||||
// The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes.
|
// The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes.
|
||||||
// See the example code in github.
|
// See the example code in GitHub.
|
||||||
//
|
//
|
||||||
// For GET, POST, PUT, PATCH and DELETE requests the respective shortcut
|
// For GET, POST, PUT, PATCH and DELETE requests the respective shortcut
|
||||||
// functions can be used.
|
// functions can be used.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user