-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutilis.go
70 lines (60 loc) · 1.46 KB
/
utilis.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 main
import (
"fmt"
"os"
)
var (
// Debug level when application is started in debug mode (--debug, --debug-level)
Debug = 0
errorsCnt int
)
// LogDebug display debugging information on stderr
func LogDebug(format string, a ...interface{}) {
if Debug > 0 {
fmt.Fprintf(os.Stderr, format, a...)
fmt.Fprintln(os.Stderr)
}
}
// LogDebug2 display debugging information on stderr when debug-level >= 2
func LogDebug2(format string, a ...interface{}) {
if Debug > 1 {
fmt.Fprintf(os.Stderr, format, a...)
fmt.Fprintln(os.Stderr)
}
}
// Log display standard messages on stderr
func Log(format string, a ...interface{}) {
fmt.Fprintf(os.Stderr, format, a...)
fmt.Fprintln(os.Stderr)
}
// LogError display error messages on stderr and continue
func LogError(format string, a ...interface{}) {
fmt.Fprintf(os.Stderr, format, a...)
fmt.Fprintln(os.Stderr)
errorsCnt++
}
// LogFatal display error messages on stderr and exit
func LogFatal(format string, a ...interface{}) {
fmt.Fprintf(os.Stderr, format, a...)
fmt.Fprintln(os.Stderr)
os.Exit(-2)
}
// AnyErrors return true when any error was logged by LogError
func AnyErrors() bool {
return errorsCnt > 0
}
// ExitWhenErrors stop application when any error was logged by LogError
func ExitWhenErrors() {
if AnyErrors() {
os.Exit(-1)
}
}
// InList return true when value exist in list
func InList(value int, list []int) bool {
for _, v := range list {
if v == value {
return true
}
}
return false
}