-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.go
73 lines (64 loc) · 1.34 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
package ltc
import (
"fmt"
"io"
"net/http"
"os"
)
const (
CHROME_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36"
)
var (
client = http.Client{}
)
// Time2Millisecond 根据分,秒,毫秒 计算出对应的毫秒值
func time2Millisecond(m, s, ms int) int {
t := m*60 + s
t *= 1000
t += ms
return t
}
// Millisecond2Time 根据毫秒值计算出对应的 时,分,秒,毫秒形式的时间值
func millisecond2Time(millisecond int) (h, m, s, ms int) {
ms = millisecond % 1000
s = millisecond / 1000
m = s / 60
h = m / 60
s %= 60
m %= 60
return
}
func ReadFile(name string) string {
if name == "" {
return ""
}
file, err := os.Open(name)
if err != nil {
fmt.Printf("打开文件失败:%v\n", err)
os.Exit(1)
}
defer func(file *os.File) {
_ = file.Close()
}(file)
data, err := io.ReadAll(file)
if err != nil {
fmt.Printf("读取文件失败:%v\n", err)
os.Exit(1)
}
return string(data)
}
func WriteFile(name string, data string) {
file, err := os.Create(name)
if err != nil {
fmt.Printf("创建结果文件失败:%v\n", err)
os.Exit(1)
}
defer func(file *os.File) {
_ = file.Close()
}(file)
nw, err := file.WriteString(data)
if err != nil || nw < len(data) {
fmt.Printf("保存文件失败:%v\n", err)
os.Exit(1)
}
}