فهرست منبع

Merge pull request #376 from jmorganca/mxyng/from-map-ignore-nil

ignore nil map values
Michael Yang 1 سال پیش
والد
کامیت
c84bbf1dd6
1فایلهای تغییر یافته به همراه4 افزوده شده و 0 حذف شده
  1. 4 0
      api/types.go

+ 4 - 0
api/types.go

@@ -216,6 +216,10 @@ func (opts *Options) FromMap(m map[string]interface{}) error {
 		if opt, ok := jsonOpts[key]; ok {
 			field := valueOpts.FieldByName(opt.Name)
 			if field.IsValid() && field.CanSet() {
+				if val == nil {
+					continue
+				}
+
 				switch field.Kind() {
 				case reflect.Int:
 					switch t := val.(type) {