This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
handlers.go
70 lines (66 loc) · 2.38 KB
/
handlers.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
package warplib
import "log"
type (
ErrorHandlerFunc func(hash string, err error)
SpawnPartHandlerFunc func(hash string, ioff, foff int64)
RespawnPartHandlerFunc func(hash string, partIoff, ioffNew, foffNew int64)
DownloadProgressHandlerFunc func(hash string, nread int)
ResumeProgressHandlerFunc func(hash string, nread int)
DownloadCompleteHandlerFunc func(hash string, tread int64)
CompileStartHandlerFunc func(hash string)
CompileProgressHandlerFunc func(hash string, nread int)
CompileSkippedHandlerFunc func(hash string, tread int64)
CompileCompleteHandlerFunc func(hash string, tread int64)
)
type Handlers struct {
SpawnPartHandler SpawnPartHandlerFunc
RespawnPartHandler RespawnPartHandlerFunc
DownloadProgressHandler DownloadProgressHandlerFunc
ResumeProgressHandler ResumeProgressHandlerFunc
ErrorHandler ErrorHandlerFunc
DownloadCompleteHandler DownloadCompleteHandlerFunc
CompileStartHandler CompileStartHandlerFunc
CompileProgressHandler CompileProgressHandlerFunc
CompileSkippedHandler CompileSkippedHandlerFunc
CompileCompleteHandler CompileCompleteHandlerFunc
}
func (h *Handlers) setDefault(l *log.Logger) {
if h.SpawnPartHandler == nil {
h.SpawnPartHandler = func(hash string, ioff, foff int64) {}
}
if h.RespawnPartHandler == nil {
h.RespawnPartHandler = func(hash string, partIoff, ioffNew, foffNew int64) {}
}
if h.DownloadProgressHandler == nil {
h.DownloadProgressHandler = func(hash string, nread int) {}
}
if h.ResumeProgressHandler == nil {
h.ResumeProgressHandler = func(hash string, nread int) {}
}
if h.DownloadCompleteHandler == nil {
h.DownloadCompleteHandler = func(hash string, tread int64) {}
}
if h.CompileStartHandler == nil {
h.CompileStartHandler = func(hash string) {}
}
if h.CompileProgressHandler == nil {
h.CompileProgressHandler = func(hash string, nread int) {}
}
if h.CompileSkippedHandler == nil {
h.CompileSkippedHandler = func(hash string, tread int64) {}
}
if h.CompileCompleteHandler == nil {
h.CompileCompleteHandler = func(hash string, tread int64) {}
}
if h.ErrorHandler == nil {
h.ErrorHandler = func(hash string, err error) {
wlog(l, "%s: Error: %s", hash, err.Error())
}
} else {
errHandler := h.ErrorHandler
h.ErrorHandler = func(hash string, err error) {
wlog(l, "%s: Error: %s", hash, err.Error())
errHandler(hash, err)
}
}
}