Skip to content

Commit

Permalink
补充字段类型处理
Browse files Browse the repository at this point in the history
  • Loading branch information
yumaojun03 committed Jun 10, 2024
1 parent 7b22985 commit a2453b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions desense/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var set = &TestMaskStuctSet{
Items: []*TestMaskStuct{
{
PhoneNumber: "1234567890123",
Name: "test",
},
},
}
Expand All @@ -48,5 +49,6 @@ func TestMuskSet(t *testing.T) {

for _, v := range set.Items {
t.Log(v.PhoneNumber)
t.Log(v.Name)
}
}
14 changes: 10 additions & 4 deletions desense/desense.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ func MaskStruct(s any) error {
switch fieldValue.Kind() {
case reflect.Slice:
for i := 0; i < fieldValue.Len(); i++ {
MaskStruct(fieldValue.Index(i).Interface())
err := MaskStruct(fieldValue.Index(i).Interface())
if err != nil {
return err
}
}
case reflect.Struct:
MaskStruct(fieldValue.Addr().Interface())
default:
case reflect.Ptr:
err := MaskStruct(fieldValue.Interface())
if err != nil {
return err
}
case reflect.String:
tag := t.Field(i).Tag.Get("mask")
if tag == "" {
continue
Expand Down

0 comments on commit a2453b5

Please sign in to comment.