-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugger.go
55 lines (46 loc) · 1002 Bytes
/
debugger.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
package main
import (
"fmt"
"time"
)
type Debugger interface {
debug(message ...interface{})
error(message ...interface{})
getErrors() []interface{}
getStatus() int
chrono(text string)
setTimer(timer time.Time)
}
type defaultdebugger struct {
Debugger
isDebugEnabled bool
timer time.Time
status int
errors []interface{}
}
func (ptr *defaultdebugger) debug(message ...interface{}) {
if ptr.isDebugEnabled {
fmt.Println(message...)
}
}
func (ptr *defaultdebugger) setTimer(time time.Time) {
ptr.timer = time
}
func (ptr *defaultdebugger) getErrors() []interface{} {
return ptr.errors
}
func (ptr *defaultdebugger) getStatus() int {
return ptr.status
}
func (ptr *defaultdebugger) error(message ...interface{}) {
if ptr.isDebugEnabled {
fmt.Println(message...)
}
ptr.status = 1
ptr.errors = append(ptr.errors, message...)
}
func (ptr *defaultdebugger) chrono(msg string) {
if ptr.isDebugEnabled {
fmt.Println(msg, time.Since(ptr.timer))
}
}