fix marshal ptr in httpc (#1789)
* fix marshal ptr in httpc * add more tests * add more tests * add more tests * fix issue on options and optional both provided
This commit is contained in:
@@ -16,7 +16,13 @@ const (
|
||||
func Marshal(val interface{}) (map[string]map[string]interface{}, error) {
|
||||
ret := make(map[string]map[string]interface{})
|
||||
tp := reflect.TypeOf(val)
|
||||
if tp.Kind() == reflect.Ptr {
|
||||
tp = tp.Elem()
|
||||
}
|
||||
rv := reflect.ValueOf(val)
|
||||
if rv.Kind() == reflect.Ptr {
|
||||
rv = rv.Elem()
|
||||
}
|
||||
|
||||
for i := 0; i < tp.NumField(); i++ {
|
||||
field := tp.Field(i)
|
||||
@@ -87,6 +93,10 @@ func validate(field reflect.StructField, value reflect.Value, opt *fieldOptions)
|
||||
return nil
|
||||
}
|
||||
|
||||
if opt.Optional && value.IsZero() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(opt.Options) > 0 {
|
||||
if err := validateOptions(value, opt); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user