Skip to content

Commit

Permalink
fix: sync map impl
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushroshan committed Dec 30, 2024
1 parent d5a0d6d commit cad794a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions internal/corazawaf/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,12 @@ var transformationNameToID = sync.Map{} // map[string]int
func transformationID(currentID int, transformationName string) int {
currName := transformationIDToName[currentID]
nextName := fmt.Sprintf("%s+%s", currName, transformationName)
if id, ok := transformationNameToID.Load(nextName); ok {
return id.(int)
}

id := len(transformationIDToName)
transformationIDToName = append(transformationIDToName, nextName)
transformationNameToID.Store(nextName, id)
return id
id, _ := transformationNameToID.LoadOrStore(nextName, func() interface{} {
txid := len(transformationIDToName)
transformationIDToName = append(transformationIDToName, nextName)
return txid
}())
return id.(int)

Check warning on line 599 in internal/corazawaf/rule.go

View check run for this annotation

Codecov / codecov/patch

internal/corazawaf/rule.go#L594-L599

Added lines #L594 - L599 were not covered by tests
}

// AddTransformation adds a transformation to the rule
Expand Down

0 comments on commit cad794a

Please sign in to comment.