Files
access-manager-api/app/localdb/utils.go
T
alu 4783d79523
tronnet/workflows: Static Analysis -- Golang / static-go (push) Successful in 30s
refactor routes,
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
2026-08-21 20:49:15 +00:00

20 lines
504 B
Go

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)
}
}
}