/
writer_option.go
42 lines (32 loc) · 1.08 KB
/
writer_option.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
package sql
import (
"github.com/alexandria-oss/streams/codec"
)
// A WriterOption is used to configure a Writer instance in an idiomatic & fine-grained way.
type WriterOption interface {
apply(*WriterConfig)
}
type egressTableOption struct {
table string
}
var _ WriterOption = egressTableOption{}
func (e egressTableOption) apply(config *WriterConfig) {
config.WriterEgressTable = e.table
}
// WithEgressTable sets the name of the table to be used as <<message egress table>>. A <<message egress table>> is
// a system database table used by `streams` mechanisms to write batch of messages to be published into a message stream.
func WithEgressTable(table string) WriterOption {
return egressTableOption{table: table}
}
type codecOption struct {
codec codec.Codec
}
var _ WriterOption = codecOption{}
func (o codecOption) apply(opts *WriterConfig) {
opts.Codec = o.codec
}
// WithCodec sets the codec.Codec to be used by Writer to encode message batches, so data may be stored into
// a database efficiently.
func WithCodec(c codec.Codec) WriterOption {
return codecOption{codec: c}
}