-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue_type.go
More file actions
63 lines (48 loc) · 1.61 KB
/
value_type.go
File metadata and controls
63 lines (48 loc) · 1.61 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
package debefix
import (
"context"
"github.com/google/uuid"
)
// ValueStaticData returns the passed static value every time it is resolved.
type ValueStaticData[T any] struct {
Value T
}
// ValueStatic returns the passed static value every time it is resolved.
func ValueStatic[T any](value T) ValueStaticData[T] {
return ValueStaticData[T]{Value: value}
}
var _ Value = (*ValueStaticData[any])(nil)
func (u ValueStaticData[T]) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error) {
return u.Value, true, nil
}
// ValueUUIDData returns a fixed [uuid.UUID] value.
type ValueUUIDData struct {
Value uuid.UUID
}
// ValueUUID returns a fixed [uuid.UUID] value.
func ValueUUID(value uuid.UUID) ValueUUIDData {
return ValueUUIDData{
Value: value,
}
}
// ValueUUIDRandom returns a fixed [uuid.UUID] value that was randomly generated on initialization.
func ValueUUIDRandom() ValueUUIDData {
return ValueUUIDData{
Value: uuid.New(),
}
}
var _ Value = (*ValueUUIDData)(nil)
func (u ValueUUIDData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error) {
return u.Value, true, nil
}
// ValueGenUUIDData returns a new random [uuid.UUID] value every time it is resolved.
type ValueGenUUIDData struct {
}
// ValueGenUUID returns a new random [uuid.UUID] value every time it is resolved.
func ValueGenUUID() ValueGenUUIDData {
return ValueGenUUIDData{}
}
var _ Value = (*ValueGenUUIDData)(nil)
func (u ValueGenUUIDData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error) {
return uuid.New(), true, nil
}