调整SetOptions的方式
This commit is contained in:
@@ -5,10 +5,8 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
|
||||
|
||||
type EmailInterface interface {
|
||||
SetOption(ctx context.Context, opt ...Option) (EmailInterface, error) // 初始化
|
||||
SetOption(ctx context.Context, opt ...Option) error // 初始化
|
||||
GetEmailType() EmailType
|
||||
// Send 发送邮件
|
||||
Send(ctx context.Context, params Message) error
|
||||
@@ -24,6 +22,7 @@ type EmailFactoryInterface interface {
|
||||
type DefaultEmail struct {
|
||||
Options Options // 配置信息
|
||||
EmailType EmailType
|
||||
IsSet bool
|
||||
}
|
||||
|
||||
func NewDefaultEmail() *DefaultEmail {
|
||||
@@ -33,15 +32,16 @@ func NewDefaultEmail() *DefaultEmail {
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DefaultEmail) SetOption(ctx context.Context, opt ...Option) (EmailInterface, error) {
|
||||
func (l *DefaultEmail) SetOption(ctx context.Context, opt ...Option) error {
|
||||
// 深复制l并且返回新的
|
||||
newL := *l
|
||||
|
||||
for _, o := range opt {
|
||||
o(&newL.Options)
|
||||
o(&l.Options)
|
||||
}
|
||||
|
||||
return &newL, nil
|
||||
l.IsSet = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *DefaultEmail) GetEmailType() EmailType {
|
||||
|
||||
Reference in New Issue
Block a user