-
Notifications
You must be signed in to change notification settings - Fork 0
/
class_kzerror.go
135 lines (101 loc) · 2.3 KB
/
class_kzerror.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package KzPack4Go
import (
"crypto/md5"
"crypto/rand"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"log"
"strings"
"github.com/satori/go.uuid"
)
type TEROR struct {
ONSTATUS bool
ERORCODE string
ERORMEMO string
DATASIZE int
LISTDATA interface{}
}
var eror error
func (self TEROR) MarshalJSON() ([]byte, error) {
var result = make(map[string]interface{})
result["ONSTATUS"] = self.ONSTATUS
result["ERORCODE"] = KzUnicode(self.ERORCODE)
result["ERORMEMO"] = KzUnicode(self.ERORMEMO)
result["DATASIZE"] = self.DATASIZE
if self.LISTDATA == nil {
self.LISTDATA = make([]interface{}, 0)
}
result["LISTDATA"] = self.LISTDATA
return json.Marshal(result)
}
func ToEROR(aERORMEMO string) TEROR {
var result TEROR
result.DATASIZE = 0
result.ONSTATUS = false
result.ERORCODE = "EROR"
result.ERORMEMO = aERORMEMO
return result
}
func ToMEMO(aERORMEMO string) TEROR {
var result TEROR
result.DATASIZE = 0
result.ONSTATUS = false
result.ERORCODE = "EROR"
result.ERORMEMO = aERORMEMO
return result
}
func ToDATA(aOnStatus bool, aErorCode string, aErorMemo string, aDataSize int, aListData interface{}) TEROR {
var result TEROR
result.ONSTATUS = aOnStatus
result.ERORCODE = aErorCode
result.ERORMEMO = aErorMemo
result.DATASIZE = aDataSize
result.LISTDATA = aListData
return result
}
func ToTRUE(aListData interface{}) TEROR {
var result TEROR
result.ONSTATUS = true
result.ERORCODE = "TRUE"
result.ERORMEMO = "TRUE"
result.LISTDATA = aListData
result.DATASIZE = 0
return result
}
func ToSIZE(aListData interface{}, aDataSize int) TEROR {
var result TEROR
result.ONSTATUS = true
result.ERORCODE = "TRUE"
result.ERORMEMO = "TRUE"
result.LISTDATA = aListData
result.DATASIZE = aDataSize
return result
}
func GetMd5String(s string) string {
h := md5.New()
h.Write([]byte(s))
return hex.EncodeToString(h.Sum(nil))
}
func ToGUID() string {
b := make([]byte, 48)
if _, err := io.ReadFull(rand.Reader, b); err != nil {
return ""
}
return strings.ToUpper(GetMd5String(base64.URLEncoding.EncodeToString(b)))
}
func ToUUID() string {
uuid, eror := uuid.NewV4()
if eror != nil {
fmt.Printf("KzPackGo.ToUUID GET WRONG.%s", eror)
return ""
}
return fmt.Sprintf("{%s}", uuid)
}
func ChEror(err error, msg string) {
if err != nil {
log.Fatalln(msg, err)
}
}