Skip to content

Commit

Permalink
Change mutex logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcast-db committed Oct 19, 2023
1 parent e790220 commit 03974b1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions common/reflect_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ func getJsonToFieldNameMap(structType reflect.Type) map[string]string {
return nil
}
mutex.Lock()
defer mutex.Unlock()
if res, ok := mapCache[structType]; ok {
res, ok := mapCache[structType]
mutex.Unlock()
if ok {
return res
}
res := map[string]string{}
res = map[string]string{}
for i := 0; i < structType.NumField(); i++ {
field := structType.Field(i)
fieldName := chooseFieldName(field)
if fieldName != "-" {
res[fieldName] = field.Name
}
}
mutex.Lock()
mapCache[structType] = res
mutex.Unlock()
return res
}

0 comments on commit 03974b1

Please sign in to comment.