mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-18 10:50:36 +00:00
Fixed panic caused by model type not being pointer in rest header spec.
This commit is contained in:
parent
9351093e2a
commit
fbc1471581
@ -1236,7 +1236,12 @@ func (h *Handler) handleUpdate(ctx context.Context, w common.ResponseWriter, id
|
||||
dataMap[pkName] = targetID
|
||||
|
||||
// Populate model instance from dataMap to preserve custom types (like SqlJSONB)
|
||||
modelInstance := reflect.New(reflect.TypeOf(model).Elem()).Interface()
|
||||
// Get the type of the model, handling both pointer and non-pointer types
|
||||
modelType := reflect.TypeOf(model)
|
||||
if modelType.Kind() == reflect.Ptr {
|
||||
modelType = modelType.Elem()
|
||||
}
|
||||
modelInstance := reflect.New(modelType).Interface()
|
||||
if err := reflection.MapToStruct(dataMap, modelInstance); err != nil {
|
||||
return fmt.Errorf("failed to populate model from data: %w", err)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user