generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.go
More file actions
64 lines (52 loc) · 1.88 KB
/
process.go
File metadata and controls
64 lines (52 loc) · 1.88 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
package configbuilder
import (
"fmt"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/enginekit/config"
)
// Process returns a new [config.Process] as configured by fn.
func Process(fn func(*ProcessBuilder)) *config.Process {
x := &ProcessBuilder{}
fn(x)
return x.Done()
}
// ProcessBuilder constructs a [config.Process].
type ProcessBuilder struct {
target config.Process
}
// TypeName sets the name of the concrete type that implements
// [dogma.ProcessMessageHandler].
func (b *ProcessBuilder) TypeName(n string) {
setTypeName(&b.target.TypeName, &b.target.Source, n)
}
// Source sets the source value to h.
func (b *ProcessBuilder) Source(h dogma.ProcessMessageHandler) {
setSource(&b.target.TypeName, &b.target.Source, h)
}
// Identity calls fn which configures a [config.Identity] that is added to the
// handler.
func (b *ProcessBuilder) Identity(fn func(*IdentityBuilder)) {
b.target.IdentityComponents = append(b.target.IdentityComponents, Identity(fn))
}
// Route calls fn which configures a [config.Route] that is added to the
// handler.
func (b *ProcessBuilder) Route(fn func(*RouteBuilder)) {
b.target.RouteComponents = append(b.target.RouteComponents, Route(fn))
}
// Disabled calls fn which configures a [config.FlagModification] that is added
// to the handler's disabled flag.
func (b *ProcessBuilder) Disabled(fn func(*FlagBuilder[config.Disabled])) {
b.target.DisabledFlags = append(b.target.DisabledFlags, Flag(fn))
}
// Partial marks the compomnent as partially configured.
func (b *ProcessBuilder) Partial(format string, args ...any) {
b.target.IsPartialReasons = append(b.target.IsPartialReasons, fmt.Sprintf(format, args...))
}
// Speculative marks the component as speculative.
func (b *ProcessBuilder) Speculative() {
b.target.IsSpeculative = true
}
// Done completes the configuration of the handler.
func (b *ProcessBuilder) Done() *config.Process {
return &b.target
}