-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
nop.go
36 lines (31 loc) · 884 Bytes
/
nop.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
package idempotency
// NOpIdempotencyGenerator is a dummy implementation of the
// IdempotencyKeyGenerator interface.
//
// Good for testing or when a predictable result is required.
type nOpIdempotencyGenerator struct {
expected string
}
const (
TestKeyExpected = "test_ikg_key"
)
// Generate encapsulates the logic to return a string representation of
// a unique idempotency key.
func (nopIKG nOpIdempotencyGenerator) Generate() string {
return nopIKG.expected
}
// NewNopGenerator returns a dummy implementation of the
// IdempotencyKeyGenerator interface.
//
// Good for testing or when a predictable result is required.
//
// If exp is an empty string, then TestKeyExpected is used as
// default value for the NOpGenerator.
func NewNopGenerator(exp string) KeyGenerator {
if exp == "" {
exp = TestKeyExpected
}
return nOpIdempotencyGenerator{
expected: exp,
}
}