-
Notifications
You must be signed in to change notification settings - Fork 0
/
observer.go
49 lines (38 loc) · 1.36 KB
/
observer.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
// Copyright (c) 2020-2021 C4 Project
//
// This file is part of c4t.
// Licenced under the MIT licence; see `LICENSE`.
package copier
import "github.com/c4-project/c4t/internal/observing"
// Observer is an interface for types that observe an SFTP file copy.
type Observer interface {
// OnCopy sends a copy observation message.
OnCopy(Message)
}
//go:generate mockery --name=Observer
// Message is the type of copy observation messages.
type Message struct {
observing.Batch
// Dst is the name of the destination file, if we're on a step.
Dst string `json:"dst,omitempty"`
// Src is the name of the source file, if we're on a step.
Src string `json:"src,omitempty"`
}
// OnCopy sends an OnCopyStep observation to multiple observers.
func OnCopy(m Message, cos ...Observer) {
for _, o := range cos {
o.OnCopy(m)
}
}
// OnCopyStart sends an OnCopyStart observation to multiple observers.
func OnCopyStart(nfiles int, cos ...Observer) {
OnCopy(Message{Batch: observing.NewBatchStart(nfiles)}, cos...)
}
// OnCopyStep sends an OnCopyStep observation to multiple observers.
func OnCopyStep(i int, dst, src string, cos ...Observer) {
OnCopy(Message{Batch: observing.NewBatchStep(i), Dst: dst, Src: src}, cos...)
}
// OnCopyEnd sends an OnCopyEnd observation to multiple observers.
func OnCopyEnd(cos ...Observer) {
OnCopy(Message{Batch: observing.NewBatchEnd()}, cos...)
}