调整SetOptions的方式

This commit is contained in:
Yun
2025-11-21 15:54:49 +08:00
parent 04bdd98d6f
commit eeaa518fc3
17 changed files with 90 additions and 86 deletions
+7 -7
View File
@@ -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 {