Open lj19950508 opened 1 year ago
i need a feture to support custom form-mapping and json-mapping like this
type A struct { field form:"field" json:"field" }
form:"field" json:"field"
form:"field"
r.UseFormMapping(defaultFormBindMapping) r.UseJsonEncodeMapping(defaultEncodingMaping) r.UseJsonDecodeMapping(defaultDecodeMapping)
type A struct { field }
func mapFormByTag(ptr interface{}, form map[string][]string, tag string) error { // Check if ptr is a map ptrVal := reflect.ValueOf(ptr) var pointed interface{} if ptrVal.Kind() == reflect.Ptr { ptrVal = ptrVal.Elem() pointed = ptrVal.Interface() } if ptrVal.Kind() == reflect.Map && ptrVal.Type().Key().Kind() == reflect.String { if pointed != nil { ptr = pointed } return setFormMap(ptr, form) }
return mappingByPtr(ptr, formSource(form), tag)
}
I agree
i need a feture to support custom form-mapping and json-mapping like this
type A struct { field
form:"field" json:"field"
}i need custom this fuction that i can bind camel key name without tag
form:"field"
r.UseFormMapping(defaultFormBindMapping) r.UseJsonEncodeMapping(defaultEncodingMaping) r.UseJsonDecodeMapping(defaultDecodeMapping)
The final result is that you don't need to use tags
type A struct { field }
this source file can be custom simply gin/binding/form_mapping.go
func mapFormByTag(ptr interface{}, form map[string][]string, tag string) error { // Check if ptr is a map ptrVal := reflect.ValueOf(ptr) var pointed interface{} if ptrVal.Kind() == reflect.Ptr { ptrVal = ptrVal.Elem() pointed = ptrVal.Interface() } if ptrVal.Kind() == reflect.Map && ptrVal.Type().Key().Kind() == reflect.String { if pointed != nil { ptr = pointed } return setFormMap(ptr, form) }
}