39
// MaskStruct replace password values with mask and returns copy of the strct.
40
// Original strct value is not modified. Doesn't go recursively through strct properties.
42
>
strctV := reflect.ValueOf(strct)
43
>
44
>
if strct == nil || (strctV.Kind() == reflect.Pointer && strctV.IsNil()) {
45
return strct
46
}
47
49
>
strctV = strctV.Elem()
50
>
}
51
52
// strctV is not a pointer now. Create a copy using assignment.
54
>
strctCopyPV := pointerTo(strctCopy)
55
>
strctCopyV := strctCopyPV.Elem()
56
>
57
>
for _, passwordFieldName := range fieldNamesToMask {
58
>
passwordF := strctCopyV.FieldByName(passwordFieldName)
59
>
if passwordF.CanSet() && passwordF.Kind() == reflect.String {
60
>
passwordF.SetString(passwordMask)
61
>
}
62
}
63
65
}
66
68
>
valPtr := reflect.New(reflect.TypeOf(val))
69
>
valPtr.Elem().Set(reflect.ValueOf(val))
70
>
return valPtr
71
>
}
72
73
func maskMap(m map[string]any, fns map[string]struct{}) {