refactor: modify directory structure

This commit is contained in:
Fu Diwei
2025-06-17 14:01:34 +08:00
parent 299a722aa9
commit 30840bbba5
346 changed files with 5051 additions and 5086 deletions

View File

@@ -6,7 +6,7 @@ import (
"log/slog"
"github.com/usual2970/certimate/internal/domain"
"github.com/usual2970/certimate/internal/pkg/core/notifier"
"github.com/usual2970/certimate/internal/pkg/core"
"github.com/usual2970/certimate/internal/repository"
)
@@ -46,20 +46,22 @@ func NewWithWorkflowNode(config NotifierWithWorkflowNodeConfig) (Notifier, error
}
}
notifierProvider, err := createNotifierProvider(options)
notifier, err := createNotifierProvider(options)
if err != nil {
return nil, err
} else {
notifier.SetLogger(config.Logger)
}
return &notifierImpl{
provider: notifierProvider.WithLogger(config.Logger),
provider: notifier,
subject: config.Subject,
message: config.Message,
}, nil
}
type notifierImpl struct {
provider notifier.Notifier
provider core.Notifier
subject string
message string
}

View File

@@ -8,7 +8,7 @@ import (
"golang.org/x/sync/errgroup"
"github.com/usual2970/certimate/internal/domain"
"github.com/usual2970/certimate/internal/pkg/core/notifier"
"github.com/usual2970/certimate/internal/pkg/core"
xmaps "github.com/usual2970/certimate/internal/pkg/utils/maps"
"github.com/usual2970/certimate/internal/repository"
)
@@ -51,7 +51,7 @@ func SendToChannel(subject, message string, channel string, channelConfig map[st
}
// Deprecated: v0.4.x 将废弃
func getEnabledNotifiers() ([]notifier.Notifier, error) {
func getEnabledNotifiers() ([]core.Notifier, error) {
settingsRepo := repository.NewSettingsRepository()
settings, err := settingsRepo.GetByName(context.Background(), "notifyChannels")
if err != nil {
@@ -63,7 +63,7 @@ func getEnabledNotifiers() ([]notifier.Notifier, error) {
return nil, fmt.Errorf("unmarshal notifyChannels error: %w", err)
}
notifiers := make([]notifier.Notifier, 0)
notifiers := make([]core.Notifier, 0)
for k, v := range rs {
if !xmaps.GetBool(v, "enabled") {
continue

View File

@@ -5,7 +5,7 @@ import (
"net/http"
"github.com/usual2970/certimate/internal/domain"
"github.com/usual2970/certimate/internal/pkg/core/notifier"
"github.com/usual2970/certimate/internal/pkg/core"
pDingTalkBot "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalkbot"
pDiscordBot "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/discordbot"
pEmail "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/email"
@@ -25,7 +25,7 @@ type notifierProviderOptions struct {
ProviderServiceConfig map[string]any
}
func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier, error) {
func createNotifierProvider(options *notifierProviderOptions) (core.Notifier, error) {
/*
注意:如果追加新的常量值,请保持以 ASCII 排序。
NOTICE: If you add new constant, please keep ASCII order.
@@ -38,7 +38,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
}
return pDingTalkBot.NewNotifier(&pDingTalkBot.NotifierConfig{
return pDingTalkBot.NewNotifierProvider(&pDingTalkBot.NotifierProviderConfig{
WebhookUrl: access.WebhookUrl,
Secret: access.Secret,
})
@@ -51,7 +51,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
}
return pDiscordBot.NewNotifier(&pDiscordBot.NotifierConfig{
return pDiscordBot.NewNotifierProvider(&pDiscordBot.NotifierProviderConfig{
BotToken: access.BotToken,
ChannelId: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "channelId", access.DefaultChannelId),
})
@@ -64,7 +64,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
}
return pEmail.NewNotifier(&pEmail.NotifierConfig{
return pEmail.NewNotifierProvider(&pEmail.NotifierProviderConfig{
SmtpHost: access.SmtpHost,
SmtpPort: access.SmtpPort,
SmtpTls: access.SmtpTls,
@@ -83,7 +83,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
}
return pLarkBot.NewNotifier(&pLarkBot.NotifierConfig{
return pLarkBot.NewNotifierProvider(&pLarkBot.NotifierProviderConfig{
WebhookUrl: access.WebhookUrl,
})
}
@@ -95,7 +95,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
}
return pMattermost.NewNotifier(&pMattermost.NotifierConfig{
return pMattermost.NewNotifierProvider(&pMattermost.NotifierProviderConfig{
ServerUrl: access.ServerUrl,
Username: access.Username,
Password: access.Password,
@@ -110,7 +110,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
}
return pSlackBot.NewNotifier(&pSlackBot.NotifierConfig{
return pSlackBot.NewNotifierProvider(&pSlackBot.NotifierProviderConfig{
BotToken: access.BotToken,
ChannelId: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "channelId", access.DefaultChannelId),
})
@@ -123,7 +123,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
}
return pTelegramBot.NewNotifier(&pTelegramBot.NotifierConfig{
return pTelegramBot.NewNotifierProvider(&pTelegramBot.NotifierProviderConfig{
BotToken: access.BotToken,
ChatId: xmaps.GetOrDefaultInt64(options.ProviderServiceConfig, "chatId", access.DefaultChatId),
})
@@ -156,7 +156,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
}
}
return pWebhook.NewNotifier(&pWebhook.NotifierConfig{
return pWebhook.NewNotifierProvider(&pWebhook.NotifierProviderConfig{
WebhookUrl: access.Url,
WebhookData: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "webhookData", access.DefaultDataForNotification),
Method: access.Method,
@@ -172,7 +172,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
}
return pWeComBot.NewNotifier(&pWeComBot.NotifierConfig{
return pWeComBot.NewNotifierProvider(&pWeComBot.NotifierProviderConfig{
WebhookUrl: access.WebhookUrl,
})
}

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/usual2970/certimate/internal/domain"
"github.com/usual2970/certimate/internal/pkg/core/notifier"
"github.com/usual2970/certimate/internal/pkg/core"
pBark "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/bark"
pDingTalk "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalkbot"
pEmail "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/email"
@@ -21,26 +21,26 @@ import (
)
// Deprecated: v0.4.x 将废弃
func createNotifierProviderUseGlobalSettings(channel domain.NotifyChannelType, channelConfig map[string]any) (notifier.Notifier, error) {
func createNotifierProviderUseGlobalSettings(channel domain.NotifyChannelType, channelConfig map[string]any) (core.Notifier, error) {
/*
注意:如果追加新的常量值,请保持以 ASCII 排序。
NOTICE: If you add new constant, please keep ASCII order.
*/
switch channel {
case domain.NotifyChannelTypeBark:
return pBark.NewNotifier(&pBark.NotifierConfig{
return pBark.NewNotifierProvider(&pBark.NotifierProviderConfig{
DeviceKey: xmaps.GetString(channelConfig, "deviceKey"),
ServerUrl: xmaps.GetString(channelConfig, "serverUrl"),
})
case domain.NotifyChannelTypeDingTalk:
return pDingTalk.NewNotifier(&pDingTalk.NotifierConfig{
return pDingTalk.NewNotifierProvider(&pDingTalk.NotifierProviderConfig{
WebhookUrl: "https://oapi.dingtalk.com/robot/send?access_token=" + xmaps.GetString(channelConfig, "accessToken"),
Secret: xmaps.GetString(channelConfig, "secret"),
})
case domain.NotifyChannelTypeEmail:
return pEmail.NewNotifier(&pEmail.NotifierConfig{
return pEmail.NewNotifierProvider(&pEmail.NotifierProviderConfig{
SmtpHost: xmaps.GetString(channelConfig, "smtpHost"),
SmtpPort: xmaps.GetInt32(channelConfig, "smtpPort"),
SmtpTls: xmaps.GetOrDefaultBool(channelConfig, "smtpTLS", true),
@@ -51,19 +51,19 @@ func createNotifierProviderUseGlobalSettings(channel domain.NotifyChannelType, c
})
case domain.NotifyChannelTypeGotify:
return pGotify.NewNotifier(&pGotify.NotifierConfig{
return pGotify.NewNotifierProvider(&pGotify.NotifierProviderConfig{
ServerUrl: xmaps.GetString(channelConfig, "url"),
Token: xmaps.GetString(channelConfig, "token"),
Priority: xmaps.GetOrDefaultInt64(channelConfig, "priority", 1),
})
case domain.NotifyChannelTypeLark:
return pLark.NewNotifier(&pLark.NotifierConfig{
return pLark.NewNotifierProvider(&pLark.NotifierProviderConfig{
WebhookUrl: xmaps.GetString(channelConfig, "webhookUrl"),
})
case domain.NotifyChannelTypeMattermost:
return pMattermost.NewNotifier(&pMattermost.NotifierConfig{
return pMattermost.NewNotifierProvider(&pMattermost.NotifierProviderConfig{
ServerUrl: xmaps.GetString(channelConfig, "serverUrl"),
ChannelId: xmaps.GetString(channelConfig, "channelId"),
Username: xmaps.GetString(channelConfig, "username"),
@@ -71,35 +71,35 @@ func createNotifierProviderUseGlobalSettings(channel domain.NotifyChannelType, c
})
case domain.NotifyChannelTypePushover:
return pPushover.NewNotifier(&pPushover.NotifierConfig{
return pPushover.NewNotifierProvider(&pPushover.NotifierProviderConfig{
Token: xmaps.GetString(channelConfig, "token"),
User: xmaps.GetString(channelConfig, "user"),
})
case domain.NotifyChannelTypePushPlus:
return pPushPlus.NewNotifier(&pPushPlus.NotifierConfig{
return pPushPlus.NewNotifierProvider(&pPushPlus.NotifierProviderConfig{
Token: xmaps.GetString(channelConfig, "token"),
})
case domain.NotifyChannelTypeServerChan:
return pServerChan.NewNotifier(&pServerChan.NotifierConfig{
return pServerChan.NewNotifierProvider(&pServerChan.NotifierProviderConfig{
ServerUrl: xmaps.GetString(channelConfig, "url"),
})
case domain.NotifyChannelTypeTelegram:
return pTelegram.NewNotifier(&pTelegram.NotifierConfig{
return pTelegram.NewNotifierProvider(&pTelegram.NotifierProviderConfig{
BotToken: xmaps.GetString(channelConfig, "apiToken"),
ChatId: xmaps.GetInt64(channelConfig, "chatId"),
})
case domain.NotifyChannelTypeWebhook:
return pWebhook.NewNotifier(&pWebhook.NotifierConfig{
return pWebhook.NewNotifierProvider(&pWebhook.NotifierProviderConfig{
WebhookUrl: xmaps.GetString(channelConfig, "url"),
AllowInsecureConnections: xmaps.GetBool(channelConfig, "allowInsecureConnections"),
})
case domain.NotifyChannelTypeWeCom:
return pWeCom.NewNotifier(&pWeCom.NotifierConfig{
return pWeCom.NewNotifierProvider(&pWeCom.NotifierProviderConfig{
WebhookUrl: xmaps.GetString(channelConfig, "webhookUrl"),
})
}