调整接口

This commit is contained in:
yun
2025-08-10 21:17:10 +08:00
parent bbeea058d0
commit 12da33399b
12 changed files with 244 additions and 150 deletions
+6 -18
View File
@@ -1,9 +1,6 @@
package mailx
import (
"context"
"errors"
"code.yun.ink/pkg/mailx/aliyun"
"code.yun.ink/pkg/mailx/aws"
"code.yun.ink/pkg/mailx/interfaces"
@@ -11,31 +8,22 @@ import (
"code.yun.ink/pkg/mailx/smtp"
)
var platform map[consts.Platform3rdType]interfaces.Email
var platform *interfaces.DefaultEmailFactory
// 注册
func init() {
platform = make(map[consts.Platform3rdType]interfaces.Email)
platform = interfaces.NewDefaultEmailFactory()
// 阿里
platform[consts.Platform3rdTypeAliyun] = &aliyun.Aliyun{}
platform.Register(aliyun.NewAliyun())
// AWS
platform[consts.Platform3rdTypeAws] = &aws.Aws{}
platform.Register(aws.NewAws())
// Smtp
platform[consts.Platform3rdTypeSmtp] = &smtp.Smtp{}
platform.Register(smtp.NewSmtp())
// mailgun
platform[consts.Platform3rdTypeMailgun] = &mailgun.MailGun{}
platform.Register(mailgun.NewMailGun())
}
func GetPlatform(ctx context.Context, plat consts.Platform3rdType) (interfaces.Email, error) {
iplat, ok := platform[plat]
if ok {
return iplat, nil
}
return nil, errors.New("not found")
}