feat: complete Kra admin backend migration
This commit is contained in:
+18
-9
@@ -17,25 +17,34 @@ import (
|
||||
)
|
||||
|
||||
type emailRepo struct {
|
||||
config *conf.AdminBackend_Email
|
||||
config *conf.AdminBackend
|
||||
}
|
||||
|
||||
func NewEmailRepo(config *conf.AdminBackend) biz.EmailRepo {
|
||||
if config == nil {
|
||||
return &emailRepo{}
|
||||
}
|
||||
return &emailRepo{config: config.Email}
|
||||
return &emailRepo{config: config}
|
||||
}
|
||||
|
||||
func (r *emailRepo) Enabled() bool {
|
||||
return r.config != nil && r.config.Host != "" && r.config.From != "" && r.config.Secret != "" && r.config.Port > 0
|
||||
}
|
||||
|
||||
func (r *emailRepo) DefaultRecipients() []string {
|
||||
func (r *emailRepo) email() *conf.AdminBackend_Email {
|
||||
if r.config == nil {
|
||||
return nil
|
||||
}
|
||||
parts := strings.Split(r.config.To, ",")
|
||||
return r.config.Email
|
||||
}
|
||||
|
||||
func (r *emailRepo) Enabled() bool {
|
||||
config := r.email()
|
||||
return config != nil && config.Host != "" && config.From != "" && config.Secret != "" && config.Port > 0
|
||||
}
|
||||
|
||||
func (r *emailRepo) DefaultRecipients() []string {
|
||||
config := r.email()
|
||||
if config == nil {
|
||||
return nil
|
||||
}
|
||||
parts := strings.Split(config.To, ",")
|
||||
result := make([]string, 0, len(parts))
|
||||
for _, part := range parts {
|
||||
if recipient := strings.TrimSpace(part); recipient != "" {
|
||||
@@ -56,7 +65,7 @@ func (r *emailRepo) Send(ctx context.Context, to []string, subject, body string)
|
||||
if len(to) == 0 {
|
||||
return errors.New("收件人不能为空")
|
||||
}
|
||||
config := r.config
|
||||
config := r.email()
|
||||
address := net.JoinHostPort(config.Host, fmt.Sprint(config.Port))
|
||||
dialer := &net.Dialer{Timeout: 10 * time.Second}
|
||||
var conn net.Conn
|
||||
|
||||
Reference in New Issue
Block a user