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

Refactor Senders initialization #797

Open
Dimedrolity opened this issue Nov 7, 2022 · 0 comments · May be fixed by #804
Open

Refactor Senders initialization #797

Dimedrolity opened this issue Nov 7, 2022 · 0 comments · May be fixed by #804

Comments

@Dimedrolity
Copy link
Contributor

Overview

We have Sender interface with Init method that configures Sender.

// Sender interface for implementing specified contact type sender
type Sender interface {
	SendEvents(events NotificationEvents, contact ContactData, trigger TriggerData, plot [][]byte, throttled bool) error
	Init(senderSettings map[string]string, logger Logger, location *time.Location, dateTimeFormat string) error
}

Problem

It is strange approach to configure entity, each Sender can have its own settings and dependencies.

Now we have logger, location *time.Location, dateTimeFormat string, I think authors (developers) wanted to don't repeat yourself and created that unified Init method. Maybe will be better extract BaseConfig struct and maybe Config struct for each Sender.

If we follow DI principle, then constructor func (that have dependencies) and Init method in one time is not well, both methods goal is to configure.

Solution

Need to create constructor functions for each Sender, and move init logic from Init method to constructors, then remove Init from interface and impelementrations.

@Dimedrolity Dimedrolity changed the title Refactor Senders configuration Refactor Senders initialization Nov 10, 2022
Dimedrolity added a commit that referenced this issue Nov 11, 2022
Use constructor function NewSender instead of Init method, remove Init method from Sender interface.
Dimedrolity added a commit that referenced this issue Nov 11, 2022
Use constructor function NewSender instead of Init method, remove Init method from Sender interface.
@Dimedrolity Dimedrolity linked a pull request Nov 11, 2022 that will close this issue
Dimedrolity added a commit that referenced this issue Nov 11, 2022
Use constructor function NewSender instead of Init method, remove Init method from Sender interface.
Dimedrolity added a commit that referenced this issue Nov 11, 2022
Use constructor function NewSender instead of Init method, remove Init method from Sender interface.
Dimedrolity added a commit that referenced this issue Nov 14, 2022
Use constructor function NewSender instead of Init method, remove Init method from Sender interface.
Dimedrolity added a commit that referenced this issue Dec 1, 2022
Use constructor function NewSender instead of Init method, remove Init method from Sender interface.
Dimedrolity added a commit that referenced this issue Dec 6, 2022
Use constructor function NewSender instead of Init method, remove Init method from Sender interface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant