-
-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathcollection.go
More file actions
90 lines (67 loc) · 2.25 KB
/
Copy pathcollection.go
File metadata and controls
90 lines (67 loc) · 2.25 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2022 Juan Pablo Tosso and the OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0
package collection
import (
"regexp"
"github.com/corazawaf/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
}
type Editable interface {
Keyed
// Remove deletes the key from the CollectionMap
Remove(key string)
// Set will replace the key's value with this slice
Set(key string, values []string)
// TODO: in v4 this should contain setters for Map and Persistence
}
// 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 {
Editable
// Add a value to some key
Add(key string, value 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)
}
// Persistent collections won't use arrays as values
// They are designed for collections that will be stored
type Persistent interface {
Editable
// // Initializes the input as the collection key
// Init(key string)
// // Sum will add the value to the key
// Sum(key string, sum int)
// // SetOne will replace the key's value with this string
// SetOne(key string, value string)
// SetTTL will set the TTL for the key
SetTTL(key string, ttl int)
}