feat: notifier

This commit is contained in:
Fu Diwei
2024-11-09 20:06:22 +08:00
parent 76fc47a274
commit 551b06b4e8
14 changed files with 350 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package email
import (
"context"
"errors"
"github.com/nikoksr/notify/service/http"
"github.com/usual2970/certimate/internal/pkg/core/notifier"
)
type WebhookNotifierConfig struct {
Url string `json:"url"`
}
type WebhookNotifier struct {
config *WebhookNotifierConfig
}
var _ notifier.Notifier = (*WebhookNotifier)(nil)
func New(config *WebhookNotifierConfig) (*WebhookNotifier, error) {
if config == nil {
return nil, errors.New("config is nil")
}
return &WebhookNotifier{
config: config,
}, nil
}
func (n *WebhookNotifier) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
srv := http.New()
srv.AddReceiversURLs(n.config.Url)
err = srv.Send(ctx, subject, message)
if err != nil {
return nil, err
}
return &notifier.NotifyResult{}, nil
}