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

Generic way to load a service #940

Open
mcarbonne opened this issue Jan 18, 2025 · 0 comments
Open

Generic way to load a service #940

mcarbonne opened this issue Jan 18, 2025 · 0 comments

Comments

@mcarbonne
Copy link

I want to migrate one of my application from shoutrrr to notify but I faced an issue: there is no way to load a service in a generic way.

With shoutrrr, a unique CreateSender function can be used to load any service:

  url := "slack://token-a/token-b/token-c"
  sender, err := shoutrrr.CreateSender(url)
  sender.Send("Hello world (or slack channel) !", map[string]string { /* ... */ })

I haven't found any generic way to do something similar with notify.

I had a look at the code and they are few possibilities to implement this.
An easy approach would be to create a function looking like this:

package notify

import "github.com/nikoksr/notify/service/slack"

func NewServiceFromURL(url string) (Notifier, error) {
        serviceName, parameters := parseURL(url)
	if serviceName == "slack" {
		return slack.New(...), nil
	} else if (...) {

	} else {
		return nil, fmt.Errorf("Service %v does not exists")
	}
}

Another approach with a map to store the associations would also be possible.

I wanted to open an issue first before submitting any PR to discuss about what can be implemented and what shall be avoided.
The solution above do avoid any breaking change. More elegant solutions might be possible but for now I only had ideas which are not backward-compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant