add support to update permissions
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-04-03 10:42:11 +11:00
parent ee822b5c9d
commit ff16acc816
5 changed files with 140 additions and 2 deletions

View File

@@ -102,3 +102,20 @@ func AppendIfNotExists[T Identifiable](slice []T, element T) []T {
// Element with the same Id does not exist, append the new element
return append(slice, element)
}
// UpdateStruct updates the values in the destination struct with values from the source struct
func UpdateStruct(dest interface{}, src interface{}) {
destValue := reflect.ValueOf(dest).Elem()
srcValue := reflect.ValueOf(src).Elem()
destType := destValue.Type()
for i := 0; i < srcValue.NumField(); i++ {
srcField := srcValue.Field(i)
destField := destValue.FieldByName(destType.Field(i).Name)
if destField.IsValid() && destField.Type() == srcField.Type() && destField.CanSet() {
destField.Set(srcField)
}
}
}