From 12809c8d64a5da3e45c41ae76a00ea2e459fbba3 Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 06:11:38 +0000 Subject: [PATCH] refactor(store): clarify journal configuration names Co-Authored-By: Virgil --- journal.go | 7 ++----- store.go | 22 +++++++++------------- store_test.go | 8 +++----- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/journal.go b/journal.go index 082a08f..7b8f92c 100644 --- a/journal.go +++ b/journal.go @@ -163,13 +163,10 @@ func (storeInstance *Store) queryJournalFlux(flux string) (string, []any, error) } func (storeInstance *Store) journalBucket() string { - if storeInstance.bucket != "" { - return storeInstance.bucket - } - if storeInstance.journal.bucketName == "" { + if storeInstance.journalConfiguration.bucketName == "" { return defaultJournalBucket } - return storeInstance.journal.bucketName + return storeInstance.journalConfiguration.bucketName } func ensureJournalSchema(database schemaDatabase) error { diff --git a/store.go b/store.go index 7532251..52a667e 100644 --- a/store.go +++ b/store.go @@ -32,7 +32,7 @@ const ( // Usage example: `storeOptions := []store.StoreOption{store.WithJournal("http://127.0.0.1:8086", "core", "events")}` type StoreOption func(*Store) -type journalDestinationConfig struct { +type journalConfiguration struct { endpointURL string organisation string bucketName string @@ -40,15 +40,13 @@ type journalDestinationConfig struct { // Usage example: `storeInstance, err := store.New(":memory:")` type Store struct { - database *sql.DB - cancelPurge context.CancelFunc - purgeWaitGroup sync.WaitGroup - purgeInterval time.Duration // interval between background purge cycles - journal journalDestinationConfig - bucket string - org string - closeLock sync.Mutex - closed bool + database *sql.DB + cancelPurge context.CancelFunc + purgeWaitGroup sync.WaitGroup + purgeInterval time.Duration // interval between background purge cycles + journalConfiguration journalConfiguration + closeLock sync.Mutex + closed bool // Event dispatch state. watchers map[string][]chan Event @@ -61,13 +59,11 @@ type Store struct { // Usage example: `storeInstance, err := store.New("/tmp/go-store.db", store.WithJournal("http://127.0.0.1:8086", "core", "events"))` func WithJournal(endpointURL, organisation, bucketName string) StoreOption { return func(storeInstance *Store) { - storeInstance.journal = journalDestinationConfig{ + storeInstance.journalConfiguration = journalConfiguration{ endpointURL: endpointURL, organisation: organisation, bucketName: bucketName, } - storeInstance.bucket = bucketName - storeInstance.org = organisation } } diff --git a/store_test.go b/store_test.go index 1963e3d..5138689 100644 --- a/store_test.go +++ b/store_test.go @@ -103,11 +103,9 @@ func TestStore_New_Good_WithJournalOption(t *testing.T) { require.NoError(t, err) defer storeInstance.Close() - assert.Equal(t, "events", storeInstance.journal.bucketName) - assert.Equal(t, "core", storeInstance.journal.organisation) - assert.Equal(t, "http://127.0.0.1:8086", storeInstance.journal.endpointURL) - assert.Equal(t, "events", storeInstance.bucket) - assert.Equal(t, "core", storeInstance.org) + assert.Equal(t, "events", storeInstance.journalConfiguration.bucketName) + assert.Equal(t, "core", storeInstance.journalConfiguration.organisation) + assert.Equal(t, "http://127.0.0.1:8086", storeInstance.journalConfiguration.endpointURL) } // ---------------------------------------------------------------------------