EventStore / EventStore-Client-Go

Go Client for Event Store version 20 and above.
Apache License 2.0
105 stars 27 forks source link

Type mismatch between `time.Duration` and time format used by EventStoreDB #103

Closed golane-christian closed 2 years ago

golane-christian commented 2 years ago

I was trying to set a maxAge for some streams and it seems like using Go's time.Duration format does not match the format expected by EventStoreDB. Steps to reproduce:

// ... init esdb.Client

streamID := "some-stream"
// Write event to stream
_, err = db.AppendToStream(context.Background(), streamID, esdb.AppendToStreamOptions{}, eventData)

// Set maxAge of stream to 1 Second
metaData := esdb.StreamMetadata{}
metaData.SetMaxAge(time.Second)
db.SetStreamMetadata(context.Background(), streamID, esdb.AppendToStreamOptions{}, metaData)

// Wait for 2 seconds
time.Sleep(time.Second*2)

// Event still exists here, can be verified using ReadStream or the admin tool (admin tool needs some stream call to refresh)

Unfortunately I don't have the time to take a closer look, so I might have missed something. Nonetheless, I wanted to leave this here for now. Taking a look at SetStreamMetadata, it seems like time.Duration values are directly marshalled to JSON, so the value is written in nanoseconds. EventstoreDB might expect another time unit, but I didn't find anything about that in the documentation. If this is not a mistake from my side, it might be worth checking all time.Duration values used in the client.

YoEight commented 2 years ago

A patch is currently under review, Thank you @golane-christian for reporting that issue!