mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 09:34:33 +08:00
uri binding successful run
This commit is contained in:
parent
e728e1c3dd
commit
638b2f47bd
@ -14,6 +14,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin/internal"
|
||||
"github.com/gin-gonic/gin/testdata/protoexample"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -645,6 +646,19 @@ func TestExistsFails(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func testUriBinding(t *testing.T, method, path, badPath, body, badBody string) {
|
||||
b := Uri
|
||||
assert.Equal(t, "uri", b.Name())
|
||||
|
||||
type Tag struct {
|
||||
Name string `uri:"name"`
|
||||
}
|
||||
var tag Tag
|
||||
params := internal.Params{internal.Param{Key: "name", Value: "thinkerou"}}
|
||||
assert.Nil(t, b.BindUri(params, &tag))
|
||||
assert.Equal(t, "thinkerou", tag.Name)
|
||||
}
|
||||
|
||||
func testFormBinding(t *testing.T, method, path, badPath, body, badBody string) {
|
||||
b := Form
|
||||
assert.Equal(t, "form", b.Name())
|
||||
|
@ -15,10 +15,19 @@ import (
|
||||
)
|
||||
|
||||
func mapUri(ptr interface{}, ps internal.Params) error {
|
||||
return nil
|
||||
var m map[string][]string
|
||||
m = make(map[string][]string)
|
||||
for _, v := range ps {
|
||||
m[v.Key] = []string{v.Value}
|
||||
}
|
||||
return mapFormByTag(ptr, m, "uri")
|
||||
}
|
||||
|
||||
func mapForm(ptr interface{}, form map[string][]string) error {
|
||||
return mapFormByTag(ptr, form, "form")
|
||||
}
|
||||
|
||||
func mapFormByTag(ptr interface{}, form map[string][]string, tag string) error {
|
||||
typ := reflect.TypeOf(ptr).Elem()
|
||||
val := reflect.ValueOf(ptr).Elem()
|
||||
for i := 0; i < typ.NumField(); i++ {
|
||||
@ -29,7 +38,7 @@ func mapForm(ptr interface{}, form map[string][]string) error {
|
||||
}
|
||||
|
||||
structFieldKind := structField.Kind()
|
||||
inputFieldName := typeField.Tag.Get("form")
|
||||
inputFieldName := typeField.Tag.Get(tag)
|
||||
inputFieldNameList := strings.Split(inputFieldName, ",")
|
||||
inputFieldName = inputFieldNameList[0]
|
||||
var defaultValue string
|
||||
|
Loading…
x
Reference in New Issue
Block a user