forked from povsister/Go-bh3-VisualNovel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
respJSON.go
53 lines (47 loc) · 812 Bytes
/
respJSON.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
package main
import (
"encoding/json"
"log"
)
type RespJSON struct {
Retcode int
Msg string
Progress int
Percent float64
Total int
}
type StateRespJSON struct {
Retcode int
AddedTime int64
Processing bool
StartedTime int64
Finished bool
EndedTime int64
Error bool
Progress int
Total int
Log string
}
func respJSON() *RespJSON {
t := RespJSON{
Retcode: 1,
Msg: "success",
Progress: 0,
Percent: 0,
}
return &t
}
func (j *RespJSON) toString() string {
respByte, err := json.Marshal(j)
if err != nil {
log.Println("JSON to string error:", err)
}
return string(respByte)
}
func (j *RespJSON) toByte() []byte {
respByte, err := json.Marshal(j)
if err != nil {
log.Println("JSON to byte error:", err)
}
return respByte
}