-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.go
81 lines (65 loc) · 1.69 KB
/
notify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2021-2024 The HeyApple Authors.
//
// Use of this source code is governed by the GNU Affero General
// Public License as published by the Free Software Foundation,
// either version 3 of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////
package mock
import (
"net/smtp"
"github.com/and-rad/heyapple/internal/app"
"github.com/jordan-wright/email"
)
type Notifier struct {
To string
Msg app.Notification
Data app.NotificationData
Err error
}
func NewNotifier() *Notifier {
return &Notifier{}
}
func (n *Notifier) WithError(err error) *Notifier {
n.Err = err
return n
}
func (n *Notifier) Send(to string, msg app.Notification, data app.NotificationData) error {
if n.Err != nil {
return n.Err
}
n.To = to
n.Msg = msg
n.Data = data
return nil
}
type EmailNotifier struct {
Email *email.Email
Server string
Err error
}
func NewEmailNotifier() *EmailNotifier {
return &EmailNotifier{}
}
func (e *EmailNotifier) WithError(err error) *EmailNotifier {
e.Err = err
return e
}
func (e *EmailNotifier) SendFunc(em *email.Email, server string, auth smtp.Auth) error {
if e.Err != nil {
return e.Err
}
e.Email = em
e.Server = server
return nil
}