-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime_router_adapter.go
58 lines (52 loc) · 1.46 KB
/
runtime_router_adapter.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
package flows
import (
"context"
"github.com/hjwalt/flows/adapter"
"github.com/hjwalt/flows/flow"
"github.com/hjwalt/flows/runtime_sarama"
"github.com/hjwalt/flows/stateless"
"github.com/hjwalt/routes/runtime_chi"
"github.com/hjwalt/runway/format"
"github.com/hjwalt/runway/inverse"
"github.com/hjwalt/runway/runtime"
"github.com/hjwalt/runway/structure"
)
// Wiring configuration
type RouterAdapterConfiguration[Request any, InputKey any, InputValue any] struct {
Name string
Path string
ProduceTopic flow.Topic[InputKey, InputValue]
ProduceBroker string
RequestBodyFormat format.Format[Request]
RequestMapFunction stateless.OneToOneFunction[structure.Bytes, Request, InputKey, InputValue]
HttpPort int
KafkaProducerConfiguration []runtime.Configuration[*runtime_sarama.Producer]
RouteConfiguration []runtime.Configuration[*runtime_chi.Runtime[context.Context]]
}
func (c RouterAdapterConfiguration[Request, InputKey, InputValue]) Register(ci inverse.Container) {
RegisterRouteConfig(
ci,
c.RouteConfiguration...,
)
RegisterProducerRoute(
ci,
"POST",
c.Path,
adapter.RouteProduceTopicBodyMapConvert(
c.RequestMapFunction,
c.RequestBodyFormat,
c.ProduceTopic,
),
)
// RUNTIME
RegisterKafkaProducer(
ci,
c.ProduceBroker,
c.KafkaProducerConfiguration,
)
RegisterRoute(
ci,
c.HttpPort,
c.RouteConfiguration,
)
}