-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
executable file
·78 lines (67 loc) · 1.35 KB
/
errors.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
package vodka
import "fmt"
var errList = map[string]int{
"Internal": 500,
}
type Error struct{
identifier string
errorMsg string
}
var NoError = Error {
identifier : "-",
errorMsg: "",
}
func NewMessageError(identifier,format string,a ...interface{}) Error{
if identifier == "-"{
return NoError
}else{
_, exist := errList[identifier]
if exist{
return Error{
identifier:identifier,
errorMsg:fmt.Sprintf(format,a...),
}
}else{
return Error{
identifier:"Internal",
errorMsg:fmt.Sprintf(format,a...),
}
}
}
}
func NewError(err error) Error{
if err == nil{
return NoError
}else{
return Error{
identifier:"Internal",
errorMsg:err.Error(),
}
}
}
func (e *Error) Error()string{
return e.errorMsg
}
func (e *Error) Identifier()string{
return e.identifier
}
func RegisterError(identifier string,statusCode int){
if identifier == "-"{
Logger.Fatalln("Register reserved identifier")
}else{
_, exist := errList[identifier]
if exist{
Logger.Fatalln("Register duplicate identifier")
}else{
errList[identifier] = statusCode
}
}
}
func MultiRegisterError(errors map[string]int){
for identifier,statusCode := range errors{
RegisterError(identifier,statusCode)
}
}
func HasError(err Error) bool{
return err.identifier != "-"
}