-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtargetdriver.go
72 lines (54 loc) · 1.6 KB
/
targetdriver.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package thunder
import (
"errors"
"github.com/quix-labs/thunder/utils"
"github.com/rs/zerolog"
"os"
)
type TargetDriverConfig struct {
Name string `json:"name"`
Config utils.DynamicConfig `json:"-"`
// As inlined SVG
Image string `json:"image,omitempty"`
Notes []string `json:"notes,omitempty"`
}
type TargetDriver interface {
ID() string
New(config any) (TargetDriver, error)
Config() TargetDriverConfig
TestConfig() (string, error) // TODO USELESS REPLACE IN FAVOR OF STATS TO CHECK NOT EMPTY
HandleEvents(processor *Processor, eventsChan <-chan TargetEvent) error
Shutdown() error
}
// Event
type TargetInsertEvent struct {
Pkey string
Version int
Json []byte
}
type TargetPatchEvent struct {
Relation *Relation
Pkey string
Version int
JsonPatch []byte
}
type TargetDeleteEvent struct {
Relation *Relation
Pkey string
}
type TargetTruncateEvent struct {
Relation *Relation
}
type TargetEvent any // TargetDeleteEvent | TargetInsertEvent | TargetPatchEvent | TargetTruncateEvent
// UTILITIES FUNCTIONS
func GetLoggerForTargetDriver(driver TargetDriver) *zerolog.Logger {
logger := zerolog.New(os.Stdout).Level(zerolog.DebugLevel).With().Str("target-driver", driver.ID()).Stack().Timestamp().Logger()
return &logger
}
// TargetDrivers is a registry that allows external library to register their own target driver
var TargetDrivers = utils.NewRegistry[TargetDriver]("target-driver").ValidateUsing(func(ID string, driver TargetDriver) error {
if driver.New == nil {
return errors.New(`target driver doesn't implements "New" method`)
}
return nil
})