From 897b70f0905091c492f22b30ba536525af9700ac Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Mon, 3 Apr 2023 20:38:38 +0000 Subject: [PATCH] feat(storage): Make Option fields exported This makes it possible to have external packages implement the storage.FS, storage.Container, and storage.File interfaces and correctly inspect the various options. --- internal/storage/options.go | 22 +++++++++++----------- internal/storage/options_test.go | 28 ++++++++++++++-------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/internal/storage/options.go b/internal/storage/options.go index e9dd1988f..2c1cf9302 100644 --- a/internal/storage/options.go +++ b/internal/storage/options.go @@ -37,8 +37,8 @@ const ( ReadWrite ) -// getOpts - iterate the inbound Options and return a struct. -func getOpts(opt ...Option) Options { +// GetOpts - iterate the inbound Options and return a struct. +func GetOpts(opt ...Option) Options { opts := getDefaultOptions() for _, o := range opt { o(&opts) @@ -48,17 +48,17 @@ func getOpts(opt ...Option) Options { func getDefaultOptions() Options { return Options{ - withCloseSyncMode: Asynchronous, - withFileAccessMode: ReadOnly, - withCreateFile: false, + WithCloseSyncMode: Asynchronous, + WithFileAccessMode: ReadOnly, + WithCreateFile: false, } } // Options are storage options. type Options struct { - withCloseSyncMode SyncMode - withFileAccessMode AccessMode - withCreateFile bool + WithCloseSyncMode SyncMode + WithFileAccessMode AccessMode + WithCreateFile bool } // Option is a storage option. @@ -67,20 +67,20 @@ type Option func(*Options) // WithCloseSyncMode sets how a file is synced when closed. func WithCloseSyncMode(m SyncMode) Option { return func(o *Options) { - o.withCloseSyncMode = m + o.WithCloseSyncMode = m } } // WithCreateFile indicates a file should be created when opening. func WithCreateFile() Option { return func(o *Options) { - o.withCreateFile = true + o.WithCreateFile = true } } // WithFileAccessMode sets the access mode when a file is opened. func WithFileAccessMode(m AccessMode) Option { return func(o *Options) { - o.withFileAccessMode = m + o.WithFileAccessMode = m } } diff --git a/internal/storage/options_test.go b/internal/storage/options_test.go index 7864ed3bf..7767df04e 100644 --- a/internal/storage/options_test.go +++ b/internal/storage/options_test.go @@ -15,43 +15,43 @@ func Test_getOpts(t *testing.T) { assert := assert.New(t) t.Run("WithCloseSyncMode", func(t *testing.T) { testOpts := getDefaultOptions() - opts := getOpts(WithCloseSyncMode(Asynchronous)) + opts := GetOpts(WithCloseSyncMode(Asynchronous)) assert.Equal(testOpts, opts) testOpts = getDefaultOptions() - opts = getOpts(WithCloseSyncMode(Synchronous)) - testOpts.withCloseSyncMode = Synchronous + opts = GetOpts(WithCloseSyncMode(Synchronous)) + testOpts.WithCloseSyncMode = Synchronous assert.Equal(opts, testOpts) testOpts = getDefaultOptions() - opts = getOpts(WithCloseSyncMode(NoSync)) - testOpts.withCloseSyncMode = NoSync + opts = GetOpts(WithCloseSyncMode(NoSync)) + testOpts.WithCloseSyncMode = NoSync assert.Equal(opts, testOpts) }) t.Run("WithFileAccessMode", func(t *testing.T) { testOpts := getDefaultOptions() - opts := getOpts(WithFileAccessMode(ReadOnly)) + opts := GetOpts(WithFileAccessMode(ReadOnly)) assert.Equal(testOpts, opts) testOpts = getDefaultOptions() - opts = getOpts(WithFileAccessMode(WriteOnly)) - testOpts.withFileAccessMode = WriteOnly + opts = GetOpts(WithFileAccessMode(WriteOnly)) + testOpts.WithFileAccessMode = WriteOnly assert.Equal(opts, testOpts) testOpts = getDefaultOptions() - opts = getOpts(WithFileAccessMode(ReadWrite)) - testOpts.withFileAccessMode = ReadWrite + opts = GetOpts(WithFileAccessMode(ReadWrite)) + testOpts.WithFileAccessMode = ReadWrite assert.Equal(opts, testOpts) }) t.Run("WithCreateFile", func(t *testing.T) { testOpts := getDefaultOptions() - opts := getOpts() - testOpts.withCreateFile = false + opts := GetOpts() + testOpts.WithCreateFile = false assert.Equal(testOpts, opts) testOpts = getDefaultOptions() - opts = getOpts(WithCreateFile()) - testOpts.withCreateFile = true + opts = GetOpts(WithCreateFile()) + testOpts.WithCreateFile = true assert.Equal(opts, testOpts) }) }