Skip to content

Commit

Permalink
feat: add cas to connector event (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmtszr authored Nov 23, 2023
1 parent da62748 commit e632aa9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func (c *connector) listener(ctx *models.ListenerContext) {
var e couchbase.Event
switch event := ctx.Event.(type) {
case models.DcpMutation:
e = couchbase.NewMutateEvent(event.Key, event.Value, event.CollectionName, event.EventTime)
e = couchbase.NewMutateEvent(event.Key, event.Value, event.CollectionName, event.EventTime, event.Cas)
case models.DcpExpiration:
e = couchbase.NewExpireEvent(event.Key, nil, event.CollectionName, event.EventTime)
e = couchbase.NewExpireEvent(event.Key, nil, event.CollectionName, event.EventTime, event.Cas)
case models.DcpDeletion:
e = couchbase.NewDeleteEvent(event.Key, nil, event.CollectionName, event.EventTime)
e = couchbase.NewDeleteEvent(event.Key, nil, event.CollectionName, event.EventTime, event.Cas)
default:
return
}
Expand Down
10 changes: 7 additions & 3 deletions couchbase/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,41 @@ type Event struct {
EventTime time.Time
Key []byte
Value []byte
Cas uint64
IsDeleted bool
IsExpired bool
IsMutated bool
}

func NewDeleteEvent(key []byte, value []byte, collectionName string, eventTime time.Time) Event {
func NewDeleteEvent(key []byte, value []byte, collectionName string, eventTime time.Time, cas uint64) Event {
return Event{
Key: key,
Value: value,
IsDeleted: true,
CollectionName: collectionName,
EventTime: eventTime,
Cas: cas,
}
}

func NewExpireEvent(key []byte, value []byte, collectionName string, eventTime time.Time) Event {
func NewExpireEvent(key []byte, value []byte, collectionName string, eventTime time.Time, cas uint64) Event {
return Event{
Key: key,
Value: value,
IsExpired: true,
CollectionName: collectionName,
EventTime: eventTime,
Cas: cas,
}
}

func NewMutateEvent(key []byte, value []byte, collectionName string, eventTime time.Time) Event {
func NewMutateEvent(key []byte, value []byte, collectionName string, eventTime time.Time, cas uint64) Event {
return Event{
Key: key,
Value: value,
IsMutated: true,
CollectionName: collectionName,
EventTime: eventTime,
Cas: cas,
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Trendyol/go-dcp-couchbase
go 1.20

require (
github.com/Trendyol/go-dcp v1.1.13
github.com/Trendyol/go-dcp v1.1.14
github.com/couchbase/gocbcore/v10 v10.2.9
github.com/prometheus/client_golang v1.17.0
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -39,7 +39,7 @@ require (
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mhmtszr/concurrent-swiss-map v1.0.4 // indirect
github.com/mhmtszr/concurrent-swiss-map v1.0.5 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/hcsshim v0.11.1 h1:hJ3s7GbWlGK4YVV92sO88BQSyF4ZLVy7/awqOlPxFbA=
github.com/Trendyol/go-dcp v1.1.13 h1:g4Ku+I5Gx+jQcxaysdEE7bOZzRVbqfLxZBSQplPVjR4=
github.com/Trendyol/go-dcp v1.1.13/go.mod h1:epMDitjzGJw9lQOUYWjBSQ8drs/4WGu6Ct3BRkeXQAM=
github.com/Trendyol/go-dcp v1.1.14 h1:jXW/UTEmDbLs+cLcp2XOCCs4j3DIzOzZOXu8Qn0m8fE=
github.com/Trendyol/go-dcp v1.1.14/go.mod h1:cvx1tjVrJ++6MCTLv8uVM1im+98eEtMM41NZ9ELfrrk=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/ansrivas/fiberprometheus/v2 v2.6.1 h1:wac3pXaE6BYYTF04AC6K0ktk6vCD+MnDOJZ3SK66kXM=
Expand Down Expand Up @@ -97,8 +97,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/mhmtszr/concurrent-swiss-map v1.0.4 h1:g1Ouq7blePtaXClzrpiGRMgFzF4DAHEHJv9OYxQkLck=
github.com/mhmtszr/concurrent-swiss-map v1.0.4/go.mod h1:F6QETL48Qn7jEJ3ZPt7EqRZjAAZu7lRQeQGIzXuUIDc=
github.com/mhmtszr/concurrent-swiss-map v1.0.5 h1:kTtd7fXymclRnwNofVI+hFq8pFndehmuXAvlZOVFq/s=
github.com/mhmtszr/concurrent-swiss-map v1.0.5/go.mod h1:F6QETL48Qn7jEJ3ZPt7EqRZjAAZu7lRQeQGIzXuUIDc=
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
Expand Down

0 comments on commit e632aa9

Please sign in to comment.