调整接口
This commit is contained in:
+26
-18
@@ -9,40 +9,48 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/ses"
|
||||
"github.com/yuninks/loggerx"
|
||||
)
|
||||
|
||||
// 不支持变更发信人(必须配置好)
|
||||
|
||||
type Aws struct {
|
||||
interfaces.DefaultEmail
|
||||
params *interfaces.EmailConfigDataAws
|
||||
logger loggerx.LoggerInterface
|
||||
// params *interfaces.EmailConfigDataAws
|
||||
}
|
||||
|
||||
func (l *Aws) InitEmail(ctx context.Context, params interfaces.EmailConfigData, logger loggerx.LoggerInterface) (interfaces.Email, error) {
|
||||
l.logger.Infof(ctx, "params:%+v", params)
|
||||
if params.Aws == nil {
|
||||
return nil, errors.New("not aws")
|
||||
}
|
||||
l.logger.Infof(ctx, "params:%+v", params.Aws)
|
||||
if params.Aws.Region == "" {
|
||||
params.Aws.Region = "ap-northeast-1"
|
||||
func NewAws() *Aws {
|
||||
aws := &Aws{}
|
||||
aws.Options = interfaces.DefaultOptions()
|
||||
aws.EmailType = "Aws"
|
||||
return aws
|
||||
}
|
||||
|
||||
func (l *Aws) SetOption(ctx context.Context, opt ...interfaces.Option) (interfaces.EmailInterface, error) {
|
||||
|
||||
for _, o := range opt {
|
||||
o(&l.Options)
|
||||
}
|
||||
|
||||
return &Aws{
|
||||
params: params.Aws,
|
||||
}, nil
|
||||
l.Options.Logger.Infof(ctx, "Aws:%+v", l.Options.Aws)
|
||||
if l.Options.Aws == nil {
|
||||
return nil, errors.New("not aws")
|
||||
}
|
||||
|
||||
if l.Options.Aws.Region == "" {
|
||||
l.Options.Aws.Region = "ap-northeast-1"
|
||||
}
|
||||
|
||||
return l, nil
|
||||
}
|
||||
|
||||
func (l *Aws) Send(ctx context.Context, params interfaces.Message) error {
|
||||
if l.params == nil {
|
||||
if l.Options.Aws == nil {
|
||||
return errors.New("not init")
|
||||
}
|
||||
// 配置AWS认证信息
|
||||
config := aws.Config{
|
||||
Region: aws.String(l.params.Region), // 设置你的AWS区域
|
||||
Credentials: credentials.NewStaticCredentials(l.params.AccessId, l.params.AccessSecret, ""),
|
||||
Region: aws.String(l.Options.Aws.Region), // 设置你的AWS区域
|
||||
Credentials: credentials.NewStaticCredentials(l.Options.Aws.AccessId, l.Options.Aws.AccessSecret, ""),
|
||||
}
|
||||
|
||||
// 创建AWS会话
|
||||
@@ -73,7 +81,7 @@ func (l *Aws) Send(ctx context.Context, params interfaces.Message) error {
|
||||
Charset: aws.String("UTF-8"),
|
||||
},
|
||||
},
|
||||
Source: aws.String(l.params.Sender),
|
||||
Source: aws.String(l.Options.Aws.Sender),
|
||||
})
|
||||
|
||||
// svc.SendRawEmail()
|
||||
|
||||
Reference in New Issue
Block a user