Skip to content

Commit

Permalink
chore: Simplify Opts.applyPushDefaults: No return value, don't call a…
Browse files Browse the repository at this point in the history
…pplyDefaultsGetDatastore. Return error from applyDefaultsGetDatastore.

Signed-off-by: Jeff Thompson <jeff@thefirst.org>
  • Loading branch information
jefft0 committed Aug 1, 2023
1 parent 89c06bb commit 2d0ab23
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,26 @@ type Opts struct {
GroupMessageStoreType string
}

func (opts *Opts) applyPushDefaults() error {
func (opts *Opts) applyPushDefaults() {
if opts.Logger == nil {
opts.Logger = zap.NewNop()
}

if opts.PrometheusRegister == nil {
opts.PrometheusRegister = prometheus.DefaultRegisterer
}

opts.applyDefaultsGetDatastore()

return nil
}

func (opts *Opts) applyDefaultsGetDatastore() {
func (opts *Opts) applyDefaultsGetDatastore() error {
if opts.RootDatastore == nil {
if opts.DatastoreDir == "" || opts.DatastoreDir == InMemoryDirectory {
opts.RootDatastore = ds_sync.MutexWrap(ds.NewMapDatastore())
} else {
opts.RootDatastore = nil
}
}

return nil
}

func (opts *Opts) applyDefaults(ctx context.Context) error {
Expand All @@ -132,12 +130,12 @@ func (opts *Opts) applyDefaults(ctx context.Context) error {

rng := mrand.New(mrand.NewSource(srand.MustSecure())) // nolint:gosec // we need to use math/rand here, but it is seeded from crypto/rand

opts.applyDefaultsGetDatastore()

if err := opts.applyPushDefaults(); err != nil {
if err := opts.applyDefaultsGetDatastore(); err != nil {
return err
}

opts.applyPushDefaults()

if opts.SecretStore == nil {
secretStore, err := secretstore.NewSecretStore(opts.RootDatastore, &secretstore.NewSecretStoreOptions{
Logger: opts.Logger,
Expand Down

0 comments on commit 2d0ab23

Please sign in to comment.