Skip to content

Commit

Permalink
condense table iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
JJTech0130 committed Jul 5, 2024
1 parent dda9d00 commit 72f27ec
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,15 @@ func (m *MetaClient) eventHandler(rawEvt any) {
}

func (m *MetaClient) handleTable(tbl *table.LSTable) {
var fields []any

tblType := reflect.TypeOf(*tbl)
tblFields := make([]any, tblType.NumField())

for i := 0; i < tblType.NumField(); i++ {
tblFields[i] = reflect.ValueOf(*tbl).Field(i).Interface()
}

for _, field := range tblFields {
if reflect.TypeOf(field).Kind() == reflect.Slice {
slice := reflect.ValueOf(field)
for i := 0; i < slice.Len(); i++ {
fields = append(fields, slice.Index(i).Interface())
tblValue := reflect.ValueOf(*tbl)
for i := 0; i < tblValue.NumField(); i++ {
field := tblValue.Field(i)
if field.Kind() == reflect.Slice {
for j := 0; j < field.Len(); j++ {
m.handleTableEvent(field.Index(j).Interface())
}
}
}

for _, field := range fields {
m.handleTableEvent(field)
}
}

func (m *MetaClient) handleTableEvent(tblEvt any) {
Expand Down

0 comments on commit 72f27ec

Please sign in to comment.