mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-10-01 12:31:59 +00:00
Update handlers skipped empty strings and nulls, so a client could not
blank or null out a column. Every key present in the payload now
overwrites the stored value, including "" and null.
- add common.MergeUpdateValues and use it in resolvespec and restheadspec
- add Handler.SetDisallowNulls to skip null values (""still overwrites)
- websocketspec and mqttspec now write only the keys present in the
payload via SetMap instead of updating the whole zeroed model, which
clobbered absent fields
24 lines
809 B
Go
24 lines
809 B
Go
package common
|
|
|
|
// MergeUpdateValues merges the incoming request values into the existing
|
|
// record map (in place) and returns it.
|
|
//
|
|
// Every key present in incoming overwrites the existing value, including empty
|
|
// strings and explicit nulls, so clients can clear a column by sending "" or
|
|
// null. Keys absent from incoming are left untouched.
|
|
//
|
|
// When disallowNulls is true, nil values are skipped and the existing value is
|
|
// kept. Empty strings are still applied.
|
|
func MergeUpdateValues(existing, incoming map[string]interface{}, disallowNulls bool) map[string]interface{} {
|
|
if existing == nil {
|
|
existing = make(map[string]interface{}, len(incoming))
|
|
}
|
|
for key, newValue := range incoming {
|
|
if newValue == nil && disallowNulls {
|
|
continue
|
|
}
|
|
existing[key] = newValue
|
|
}
|
|
return existing
|
|
}
|