Skip to content

Commit

Permalink
chore: do not try to parse config
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <[email protected]>
  • Loading branch information
rustatian committed Nov 22, 2024
1 parent 2c83194 commit 1ced35e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 39 deletions.
14 changes: 0 additions & 14 deletions memorykv/config.go

This file was deleted.

25 changes: 2 additions & 23 deletions memorykv/kv.go → memorykv/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,9 @@ type Driver struct {

tracer *sdktrace.TracerProvider
log *zap.Logger
cfg *Config
}

type Configurer interface {
// UnmarshalKey takes a single key and unmarshal it into a Struct.
UnmarshalKey(name string, out any) error
// Has checks if config section exists.
Has(name string) bool
}

func NewInMemoryDriver(key string, log *zap.Logger, cfgPlugin Configurer, tracer *sdktrace.TracerProvider) (*Driver, error) {
const op = errors.Op("new_in_memory_driver")

func NewInMemoryDriver(log *zap.Logger, tracer *sdktrace.TracerProvider) *Driver {
if tracer == nil {
tracer = sdktrace.NewTracerProvider()
}
Expand All @@ -56,18 +46,7 @@ func NewInMemoryDriver(key string, log *zap.Logger, cfgPlugin Configurer, tracer
ch := make(chan struct{})
d.broadcastStopCh.Store(&ch)

err := cfgPlugin.UnmarshalKey(key, &d.cfg)
if err != nil {
return nil, errors.E(op, err)
}

if d.cfg == nil {
return nil, errors.E(op, errors.Errorf("config not found by provided key: %s", key))
}

d.cfg.InitDefaults()

return d, nil
return d
}

func (d *Driver) Has(keys ...string) (map[string]bool, error) {
Expand Down
4 changes: 2 additions & 2 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (p *Plugin) Collects() []*dep.In {

// Drivers implementation

func (p *Plugin) KvFromConfig(key string) (kv.Storage, error) {
return memorykv.NewInMemoryDriver(key, p.log, p.cfg, p.tracer)
func (p *Plugin) KvFromConfig(_ string) (kv.Storage, error) {
return memorykv.NewInMemoryDriver(p.log, p.tracer), nil
}

// DriverFromConfig constructs a memory driver from the .rr.yaml configuration
Expand Down

0 comments on commit 1ced35e

Please sign in to comment.