调整接口
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user