strategy/email/email.go   A
last analyzed

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 22
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A email.Get 0 5 1
A email.*Strategy.Write 0 7 1
1
////////////////////////////////////////////////////////////////////////////////
2
// Author:   Nikita Koryabkin
3
// Email:    [email protected]
4
// Telegram: https://t.me/Apologiz
5
////////////////////////////////////////////////////////////////////////////////
6
7
package email
8
9
import (
10
	"github.com/mylockerteam/mailSender"
11
	"gopkg.in/gomail.v2"
12
	"html/template"
13
	"io"
14
)
15
16
// Strategy logging strategy in the email
17
// You can use it for errors and other types of messages
18
type Strategy struct {
19
	sender   mailSender.AsyncSender
20
	Message  *gomail.Message
21
	Template *template.Template
22
	io.Writer
23
}
24
25
//Get waiting for a parameter ess in format host:port;username;password
26
func Get(sender mailSender.AsyncSender, msg *gomail.Message, tpl *template.Template) io.Writer {
27
	return &Strategy{
28
		sender:   sender,
29
		Message:  msg,
30
		Template: tpl,
31
	}
32
}
33
34
func (s *Strategy) Write(p []byte) (n int, err error) {
35
	s.sender.SendAsync(mailSender.Message{
36
		Message:  s.Message,
37
		Template: s.Template,
38
		Data:     mailSender.EmailData{"Data": string(p)},
39
	})
40
	return len(p), nil
41
}
42