-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifier.go
183 lines (147 loc) · 5.69 KB
/
notifier.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2020 The goftp Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package ftp
// Notifier represents a notification operator interface
type Notifier interface {
BeforeCommand(ctx *Context, command string)
BeforeLoginUser(ctx *Context, userName string)
BeforePutFile(ctx *Context, dstPath string)
BeforeDeleteFile(ctx *Context, dstPath string)
BeforeChangeCurDir(ctx *Context, oldCurDir, newCurDir string)
BeforeCreateDir(ctx *Context, dstPath string)
BeforeDeleteDir(ctx *Context, dstPath string)
BeforeDownloadFile(ctx *Context, dstPath string)
AfterUserLogin(ctx *Context, userName, password string, passMatched bool, err error)
AfterFilePut(ctx *Context, dstPath string, size int64, err error)
AfterFileDeleted(ctx *Context, dstPath string, err error)
AfterFileDownloaded(ctx *Context, dstPath string, size int64, err error)
AfterCurDirChanged(ctx *Context, oldCurDir, newCurDir string, err error)
AfterDirCreated(ctx *Context, dstPath string, err error)
AfterDirDeleted(ctx *Context, dstPath string, err error)
}
type notifierList []Notifier
var _ Notifier = notifierList{}
func (notifiers notifierList) BeforeCommand(ctx *Context, command string) {
for _, notifier := range notifiers {
notifier.BeforeCommand(ctx, command)
}
}
func (notifiers notifierList) BeforeLoginUser(ctx *Context, userName string) {
for _, notifier := range notifiers {
notifier.BeforeLoginUser(ctx, userName)
}
}
func (notifiers notifierList) BeforePutFile(ctx *Context, dstPath string) {
for _, notifier := range notifiers {
notifier.BeforePutFile(ctx, dstPath)
}
}
func (notifiers notifierList) BeforeDeleteFile(ctx *Context, dstPath string) {
for _, notifier := range notifiers {
notifier.BeforeDeleteFile(ctx, dstPath)
}
}
func (notifiers notifierList) BeforeChangeCurDir(ctx *Context, oldCurDir, newCurDir string) {
for _, notifier := range notifiers {
notifier.BeforeChangeCurDir(ctx, oldCurDir, newCurDir)
}
}
func (notifiers notifierList) BeforeCreateDir(ctx *Context, dstPath string) {
for _, notifier := range notifiers {
notifier.BeforeCreateDir(ctx, dstPath)
}
}
func (notifiers notifierList) BeforeDeleteDir(ctx *Context, dstPath string) {
for _, notifier := range notifiers {
notifier.BeforeDeleteDir(ctx, dstPath)
}
}
func (notifiers notifierList) BeforeDownloadFile(ctx *Context, dstPath string) {
for _, notifier := range notifiers {
notifier.BeforeDownloadFile(ctx, dstPath)
}
}
func (notifiers notifierList) AfterUserLogin(ctx *Context, userName, password string, passMatched bool, err error) {
for _, notifier := range notifiers {
notifier.AfterUserLogin(ctx, userName, password, passMatched, err)
}
}
func (notifiers notifierList) AfterFilePut(ctx *Context, dstPath string, size int64, err error) {
for _, notifier := range notifiers {
notifier.AfterFilePut(ctx, dstPath, size, err)
}
}
func (notifiers notifierList) AfterFileDeleted(ctx *Context, dstPath string, err error) {
for _, notifier := range notifiers {
notifier.AfterFileDeleted(ctx, dstPath, err)
}
}
func (notifiers notifierList) AfterFileDownloaded(ctx *Context, dstPath string, size int64, err error) {
for _, notifier := range notifiers {
notifier.AfterFileDownloaded(ctx, dstPath, size, err)
}
}
func (notifiers notifierList) AfterCurDirChanged(ctx *Context, oldCurDir, newCurDir string, err error) {
for _, notifier := range notifiers {
notifier.AfterCurDirChanged(ctx, oldCurDir, newCurDir, err)
}
}
func (notifiers notifierList) AfterDirCreated(ctx *Context, dstPath string, err error) {
for _, notifier := range notifiers {
notifier.AfterDirCreated(ctx, dstPath, err)
}
}
func (notifiers notifierList) AfterDirDeleted(ctx *Context, dstPath string, err error) {
for _, notifier := range notifiers {
notifier.AfterDirDeleted(ctx, dstPath, err)
}
}
// NullNotifier implements Notifier
type NullNotifier struct{}
var _ Notifier = &NullNotifier{}
// BeforeCommand implements Notifier
func (NullNotifier) BeforeCommand(ctx *Context, command string) {
}
// BeforeLoginUser implements Notifier
func (NullNotifier) BeforeLoginUser(ctx *Context, userName string) {
}
// BeforePutFile implements Notifier
func (NullNotifier) BeforePutFile(ctx *Context, dstPath string) {
}
// BeforeDeleteFile implements Notifier
func (NullNotifier) BeforeDeleteFile(ctx *Context, dstPath string) {
}
// BeforeChangeCurDir implements Notifier
func (NullNotifier) BeforeChangeCurDir(ctx *Context, oldCurDir, newCurDir string) {
}
// BeforeCreateDir implements Notifier
func (NullNotifier) BeforeCreateDir(ctx *Context, dstPath string) {
}
// BeforeDeleteDir implements Notifier
func (NullNotifier) BeforeDeleteDir(ctx *Context, dstPath string) {
}
// BeforeDownloadFile implements Notifier
func (NullNotifier) BeforeDownloadFile(ctx *Context, dstPath string) {
}
// AfterUserLogin implements Notifier
func (NullNotifier) AfterUserLogin(ctx *Context, userName, password string, passMatched bool, err error) {
}
// AfterFilePut implements Notifier
func (NullNotifier) AfterFilePut(ctx *Context, dstPath string, size int64, err error) {
}
// AfterFileDeleted implements Notifier
func (NullNotifier) AfterFileDeleted(ctx *Context, dstPath string, err error) {
}
// AfterFileDownloaded implements Notifier
func (NullNotifier) AfterFileDownloaded(ctx *Context, dstPath string, size int64, err error) {
}
// AfterCurDirChanged implements Notifier
func (NullNotifier) AfterCurDirChanged(ctx *Context, oldCurDir, newCurDir string, err error) {
}
// AfterDirCreated implements Notifier
func (NullNotifier) AfterDirCreated(ctx *Context, dstPath string, err error) {
}
// AfterDirDeleted implements Notifier
func (NullNotifier) AfterDirDeleted(ctx *Context, dstPath string, err error) {
}