refactor: normalize providers constructors
This commit is contained in:
@@ -9,28 +9,28 @@ import (
|
||||
"github.com/usual2970/certimate/internal/pkg/core/notifier"
|
||||
)
|
||||
|
||||
type ServerChanNotifierConfig struct {
|
||||
type NotifierConfig struct {
|
||||
// ServerChan 服务地址。
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type ServerChanNotifier struct {
|
||||
config *ServerChanNotifierConfig
|
||||
type NotifierProvider struct {
|
||||
config *NotifierConfig
|
||||
}
|
||||
|
||||
var _ notifier.Notifier = (*ServerChanNotifier)(nil)
|
||||
var _ notifier.Notifier = (*NotifierProvider)(nil)
|
||||
|
||||
func New(config *ServerChanNotifierConfig) (*ServerChanNotifier, error) {
|
||||
func NewNotifier(config *NotifierConfig) (*NotifierProvider, error) {
|
||||
if config == nil {
|
||||
panic("config is nil")
|
||||
}
|
||||
|
||||
return &ServerChanNotifier{
|
||||
return &NotifierProvider{
|
||||
config: config,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (n *ServerChanNotifier) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
|
||||
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
|
||||
srv := notifyHttp.New()
|
||||
|
||||
srv.AddReceivers(¬ifyHttp.Webhook{
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestNotify(t *testing.T) {
|
||||
fmt.Sprintf("URL: %v", fUrl),
|
||||
}, "\n"))
|
||||
|
||||
notifier, err := provider.New(&provider.ServerChanNotifierConfig{
|
||||
notifier, err := provider.NewNotifier(&provider.NotifierConfig{
|
||||
Url: fUrl,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user