use json encoding for route body parameters, implement modify user/group/pool operations, simplify schema by using comon lib struct tags and RequireAll and AtLeastOne helper functions, properly implement locadb as Backend interface
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package localdb
|
||||
|
||||
import "reflect"
|
||||
|
||||
// MergeNonZero overwrites fields in dst with fields in src iff src is not a zero value.
|
||||
func MergeNonZero[T any](dst *T, src *T) {
|
||||
vDst := reflect.ValueOf(dst).Elem()
|
||||
vSrc := reflect.ValueOf(src).Elem()
|
||||
|
||||
for i := 0; i < vDst.NumField(); i++ {
|
||||
dstField := vDst.Field(i)
|
||||
srcField := vSrc.Field(i)
|
||||
|
||||
// Only set if the field is exported (CanSet) and the source is not a zero value
|
||||
if dstField.CanSet() && !srcField.IsZero() {
|
||||
dstField.Set(srcField)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user