mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
refactor: clean code
This commit is contained in:
parent
12d0b66c61
commit
dd2087b101
@ -6,13 +6,13 @@ import (
|
|||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/notifier"
|
"github.com/usual2970/certimate/internal/pkg/core/notifier"
|
||||||
pDingTalk "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalk"
|
pDingTalkBot "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalkbot"
|
||||||
pEmail "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/email"
|
pEmail "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/email"
|
||||||
pLark "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/lark"
|
pLarkBot "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/larkbot"
|
||||||
pMattermost "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/mattermost"
|
pMattermost "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/mattermost"
|
||||||
pTelegram "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/telegram"
|
pTelegram "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/telegram"
|
||||||
pWebhook "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/webhook"
|
pWebhook "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/webhook"
|
||||||
pWeCom "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/wecom"
|
pWeComBot "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/wecombot"
|
||||||
httputil "github.com/usual2970/certimate/internal/pkg/utils/http"
|
httputil "github.com/usual2970/certimate/internal/pkg/utils/http"
|
||||||
maputil "github.com/usual2970/certimate/internal/pkg/utils/map"
|
maputil "github.com/usual2970/certimate/internal/pkg/utils/map"
|
||||||
)
|
)
|
||||||
@ -36,7 +36,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
|
|||||||
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
|
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pDingTalk.NewNotifier(&pDingTalk.NotifierConfig{
|
return pDingTalkBot.NewNotifier(&pDingTalkBot.NotifierConfig{
|
||||||
WebhookUrl: access.WebhookUrl,
|
WebhookUrl: access.WebhookUrl,
|
||||||
Secret: access.Secret,
|
Secret: access.Secret,
|
||||||
})
|
})
|
||||||
@ -67,7 +67,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
|
|||||||
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
|
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pLark.NewNotifier(&pLark.NotifierConfig{
|
return pLarkBot.NewNotifier(&pLarkBot.NotifierConfig{
|
||||||
WebhookUrl: access.WebhookUrl,
|
WebhookUrl: access.WebhookUrl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ func createNotifierProvider(options *notifierProviderOptions) (notifier.Notifier
|
|||||||
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
|
return nil, fmt.Errorf("failed to populate provider access config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pWeCom.NewNotifier(&pWeCom.NotifierConfig{
|
return pWeComBot.NewNotifier(&pWeComBot.NotifierConfig{
|
||||||
WebhookUrl: access.WebhookUrl,
|
WebhookUrl: access.WebhookUrl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,17 @@ import (
|
|||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/pkg/core/notifier"
|
"github.com/usual2970/certimate/internal/pkg/core/notifier"
|
||||||
pBark "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/bark"
|
pBark "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/bark"
|
||||||
pDingTalk "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalk"
|
pDingTalk "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalkbot"
|
||||||
pEmail "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/email"
|
pEmail "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/email"
|
||||||
pGotify "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/gotify"
|
pGotify "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/gotify"
|
||||||
pLark "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/lark"
|
pLark "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/larkbot"
|
||||||
pMattermost "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/mattermost"
|
pMattermost "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/mattermost"
|
||||||
pPushover "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/pushover"
|
pPushover "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/pushover"
|
||||||
pPushPlus "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/pushplus"
|
pPushPlus "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/pushplus"
|
||||||
pServerChan "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/serverchan"
|
pServerChan "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/serverchan"
|
||||||
pTelegram "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/telegram"
|
pTelegram "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/telegram"
|
||||||
pWebhook "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/webhook"
|
pWebhook "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/webhook"
|
||||||
pWeCom "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/wecom"
|
pWeCom "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/wecombot"
|
||||||
maputil "github.com/usual2970/certimate/internal/pkg/utils/map"
|
maputil "github.com/usual2970/certimate/internal/pkg/utils/map"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package dingtalk
|
package dingtalkbot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package dingtalk_test
|
package dingtalkbot_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalk"
|
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/dingtalkbot"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -16,22 +16,23 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
fAccessToken string
|
fWebhookUrl string
|
||||||
fSecret string
|
fSecret string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
argsPrefix := "CERTIMATE_NOTIFIER_DINGTALK_"
|
argsPrefix := "CERTIMATE_NOTIFIER_DINGTALKBOT_"
|
||||||
|
|
||||||
flag.StringVar(&fAccessToken, argsPrefix+"ACCESSTOKEN", "", "")
|
flag.StringVar(&fWebhookUrl, argsPrefix+"WEBHOOKURL", "", "")
|
||||||
flag.StringVar(&fSecret, argsPrefix+"SECRET", "", "")
|
flag.StringVar(&fSecret, argsPrefix+"SECRET", "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Shell command to run this test:
|
Shell command to run this test:
|
||||||
|
|
||||||
go test -v ./dingtalk_test.go -args \
|
go test -v ./dingtalkbot_test.go -args \
|
||||||
--CERTIMATE_NOTIFIER_DINGTALK_URL="https://example.com/your-webhook-url"
|
--CERTIMATE_NOTIFIER_DINGTALKBOT_WEBHOOKURL="https://example.com/your-webhook-url" \
|
||||||
|
--CERTIMATE_NOTIFIER_DINGTALKBOT_SECRET="your-secret"
|
||||||
*/
|
*/
|
||||||
func TestNotify(t *testing.T) {
|
func TestNotify(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -39,12 +40,12 @@ func TestNotify(t *testing.T) {
|
|||||||
t.Run("Notify", func(t *testing.T) {
|
t.Run("Notify", func(t *testing.T) {
|
||||||
t.Log(strings.Join([]string{
|
t.Log(strings.Join([]string{
|
||||||
"args:",
|
"args:",
|
||||||
fmt.Sprintf("ACCESSTOKEN: %v", fAccessToken),
|
fmt.Sprintf("WEBHOOKURL: %v", fWebhookUrl),
|
||||||
fmt.Sprintf("SECRET: %v", fSecret),
|
fmt.Sprintf("SECRET: %v", fSecret),
|
||||||
}, "\n"))
|
}, "\n"))
|
||||||
|
|
||||||
notifier, err := provider.NewNotifier(&provider.NotifierConfig{
|
notifier, err := provider.NewNotifier(&provider.NotifierConfig{
|
||||||
AccessToken: fAccessToken,
|
WebhookUrl: fWebhookUrl,
|
||||||
Secret: fSecret,
|
Secret: fSecret,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
@ -1,4 +1,4 @@
|
|||||||
package lark
|
package larkbot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package serverchan_test
|
package larkbot_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/wecom"
|
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/larkbot"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -18,7 +18,7 @@ const (
|
|||||||
var fWebhookUrl string
|
var fWebhookUrl string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
argsPrefix := "CERTIMATE_NOTIFIER_WECOM_"
|
argsPrefix := "CERTIMATE_NOTIFIER_LARKBOT_"
|
||||||
|
|
||||||
flag.StringVar(&fWebhookUrl, argsPrefix+"WEBHOOKURL", "", "")
|
flag.StringVar(&fWebhookUrl, argsPrefix+"WEBHOOKURL", "", "")
|
||||||
}
|
}
|
||||||
@ -26,8 +26,8 @@ func init() {
|
|||||||
/*
|
/*
|
||||||
Shell command to run this test:
|
Shell command to run this test:
|
||||||
|
|
||||||
go test -v ./wecom_test.go -args \
|
go test -v ./larkbot_test.go -args \
|
||||||
--CERTIMATE_NOTIFIER_WECOM_WEBHOOKURL="https://example.com/your-webhook-url" \
|
--CERTIMATE_NOTIFIER_LARKBOT_WEBHOOKURL="https://example.com/your-webhook-url"
|
||||||
*/
|
*/
|
||||||
func TestNotify(t *testing.T) {
|
func TestNotify(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
@ -1,4 +1,4 @@
|
|||||||
package serverchan
|
package wecombot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package lark_test
|
package wecombot_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/lark"
|
provider "github.com/usual2970/certimate/internal/pkg/core/notifier/providers/wecombot"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -18,7 +18,7 @@ const (
|
|||||||
var fWebhookUrl string
|
var fWebhookUrl string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
argsPrefix := "CERTIMATE_NOTIFIER_LARK_"
|
argsPrefix := "CERTIMATE_NOTIFIER_WECOMBOT_"
|
||||||
|
|
||||||
flag.StringVar(&fWebhookUrl, argsPrefix+"WEBHOOKURL", "", "")
|
flag.StringVar(&fWebhookUrl, argsPrefix+"WEBHOOKURL", "", "")
|
||||||
}
|
}
|
||||||
@ -26,8 +26,8 @@ func init() {
|
|||||||
/*
|
/*
|
||||||
Shell command to run this test:
|
Shell command to run this test:
|
||||||
|
|
||||||
go test -v ./lark_test.go -args \
|
go test -v ./wecombot_test.go -args \
|
||||||
--CERTIMATE_NOTIFIER_LARK_WEBHOOKURL="https://example.com/your-webhook-url"
|
--CERTIMATE_NOTIFIER_WECOMBOT_WEBHOOKURL="https://example.com/your-webhook-url" \
|
||||||
*/
|
*/
|
||||||
func TestNotify(t *testing.T) {
|
func TestNotify(t *testing.T) {
|
||||||
flag.Parse()
|
flag.Parse()
|
Loading…
x
Reference in New Issue
Block a user