Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: do not try to parse config #156

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading