forked from mousycoder/xxl-job-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
86 lines (70 loc) · 1.3 KB
/
util.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
package xxl
import (
"encoding/json"
"net"
"strconv"
)
//int64 to str
func Int64ToStr(i int64) string {
return strconv.FormatInt(i, 10)
}
//str to int64
func StrToInt64(str string) int64 {
i, _ := strconv.ParseInt(str, 10, 64)
return i
}
// LocalIPs return all non-loopback IPv4 addresses
func LocalIPv4s() ([]string, error) {
var ips []string
addrs, err := net.InterfaceAddrs()
if err != nil {
return ips, err
}
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.To4() != nil {
ips = append(ips, ipnet.IP.String())
}
}
return ips, nil
}
func LocalIP() string {
ips, _ := LocalIPv4s()
return ips[0]
}
//执行任务回调
func returnCall(req *RunReq, code int64, msg string) []byte {
data := call{
&callElement{
LogID: req.LogID,
LogDateTim: req.LogDateTime,
ExecuteResult: &ExecuteResult{
Code: code,
Msg: msg,
},
},
}
str, _ := json.Marshal(data)
return str
}
//杀死任务返回
func returnKill(req *killReq, code int64) []byte {
msg := ""
if code != 200 {
msg = "Task kill err"
}
data := res{
Code: code,
Msg: msg,
}
str, _ := json.Marshal(data)
return str
}
//通用返回
func returnGeneral() []byte {
data := &res{
Code: 200,
Msg: "",
}
str, _ := json.Marshal(data)
return str
}