-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.go
44 lines (40 loc) · 869 Bytes
/
response.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
package coco
// Result 返回结果
type Result struct {
Type string `json:"-"` // object or binary
Code int `json:"code"`
Data interface{} `json:"data"`
BinaryData []byte `json:"-"`
Message string `json:"message"`
FileName string `json:"-"`
}
func APIResponse(data interface{}) Result {
return Result{
Type: "object",
Code: 0,
Data: data,
Message: "",
BinaryData: nil,
FileName: "",
}
}
func ErrorResponse(code int) Result {
return Result{
Type: "object",
Code: code,
Data: nil,
Message: "",
BinaryData: nil,
FileName: "",
}
}
func FileResponse(fileName string, content []byte) Result {
return Result{
Type: "binary",
Code: 0,
Data: nil,
Message: "",
BinaryData: content,
FileName: fileName,
}
}