-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collection.go
66 lines (50 loc) · 1.7 KB
/
collection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2022 Juan Pablo Tosso and the OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0
package collection
import (
"regexp"
"github.com/appsentinels/coraza/v3/types"
)
// Collection are used to store VARIABLE data
// for transactions, this data structured is designed
// to store slices of data for keys
// Important: CollectionMaps ARE NOT concurrent safe
type Collection interface {
// FindAll returns matches for all the items in this Collection.
FindAll() []types.MatchData
// Name returns the name for the current CollectionMap
Name() string
}
// Single is a Collection with a single element.
type Single interface {
Collection
// Get returns the value of this Single
Get() string
}
// Keyed is a Collection with elements that can be selected by key.
type Keyed interface {
Collection
// Get returns a slice of strings for a key
Get(key string) []string
// FindRegex returns a slice of MatchData for the regex
FindRegex(key *regexp.Regexp) []types.MatchData
// FindString returns a slice of MatchData for the string
FindString(key string) []types.MatchData
}
// Map are used to store VARIABLE data
// for transactions, this data structured is designed
// to store slices of data for keys
// Important: CollectionMaps ARE NOT concurrent safe
type Map interface {
Keyed
// Add a value to some key
Add(key string, value string)
// Set will replace the key's value with this slice
Set(key string, values []string)
// SetIndex will place the value under the index
// If the index is higher than the current size of the CollectionMap
// it will be appended
SetIndex(key string, index int, value string)
// Remove deletes the key from the CollectionMap
Remove(key string)
}