-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdestination.go
58 lines (47 loc) · 1.77 KB
/
destination.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 connectorname
import (
"context"
"github.com/conduitio/conduit-commons/opencdc"
sdk "github.com/conduitio/conduit-connector-sdk"
)
type Destination struct {
sdk.UnimplementedDestination
config DestinationConfig
}
type DestinationConfig struct {
sdk.DefaultDestinationMiddleware
// Config includes parameters that are the same in the source and destination.
Config
// DestinationConfigParam must be either yes or no (defaults to yes).
DestinationConfigParam string `validate:"inclusion=yes|no" default:"yes"`
}
func (s *DestinationConfig) Validate(context.Context) error {
// Custom validation or parsing should be implemented here.
return nil
}
func NewDestination() sdk.Destination {
// Create Destination and wrap it in the default middleware.
return sdk.DestinationWithMiddleware(&Destination{})
}
func (d *Destination) Config() sdk.DestinationConfig {
return &d.config
}
func (d *Destination) Open(_ context.Context) error {
// Open is called after Configure to signal the plugin it can prepare to
// start writing records. If needed, the plugin should open connections in
// this function.
return nil
}
func (d *Destination) Write(_ context.Context, _ []opencdc.Record) (int, error) {
// Write writes len(r) records from r to the destination right away without
// caching. It should return the number of records written from r
// (0 <= n <= len(r)) and any error encountered that caused the write to
// stop early. Write must return a non-nil error if it returns n < len(r).
return 0, nil
}
func (d *Destination) Teardown(_ context.Context) error {
// Teardown signals to the plugin that all records were written and there
// will be no more calls to any other function. After Teardown returns, the
// plugin should be ready for a graceful shutdown.
return nil
}