refactor: normalize providers constructors
This commit is contained in:
@@ -8,30 +8,30 @@ import (
|
||||
"github.com/usual2970/certimate/internal/pkg/core/notifier"
|
||||
)
|
||||
|
||||
type TelegramNotifierConfig struct {
|
||||
type NotifierConfig struct {
|
||||
// Telegram API Token。
|
||||
ApiToken string `json:"apiToken"`
|
||||
// Telegram Chat ID。
|
||||
ChatId int64 `json:"chatId"`
|
||||
}
|
||||
|
||||
type TelegramNotifier struct {
|
||||
config *TelegramNotifierConfig
|
||||
type NotifierProvider struct {
|
||||
config *NotifierConfig
|
||||
}
|
||||
|
||||
var _ notifier.Notifier = (*TelegramNotifier)(nil)
|
||||
var _ notifier.Notifier = (*NotifierProvider)(nil)
|
||||
|
||||
func New(config *TelegramNotifierConfig) (*TelegramNotifier, error) {
|
||||
func NewNotifier(config *NotifierConfig) (*NotifierProvider, error) {
|
||||
if config == nil {
|
||||
panic("config is nil")
|
||||
}
|
||||
|
||||
return &TelegramNotifier{
|
||||
return &NotifierProvider{
|
||||
config: config,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (n *TelegramNotifier) 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, err := telegram.New(n.config.ApiToken)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestNotify(t *testing.T) {
|
||||
fmt.Sprintf("CHATID: %v", fChartId),
|
||||
}, "\n"))
|
||||
|
||||
notifier, err := provider.New(&provider.TelegramNotifierConfig{
|
||||
notifier, err := provider.NewNotifier(&provider.NotifierConfig{
|
||||
ApiToken: fApiToken,
|
||||
ChatId: fChartId,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user