-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
62 lines (50 loc) · 1.29 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package client
import (
"fmt"
httpi "github.com/hopeio/cherry/utils/net/http"
"github.com/hopeio/cherry/utils/net/http/client"
)
type ResponseBody[RES any] httpi.ResData[RES]
func CommonResponse[RES any]() client.ResponseBodyCheck {
return &ResponseBody[RES]{}
}
func (res *ResponseBody[RES]) CheckError() error {
if res.Code != 0 {
return fmt.Errorf("code: %d, message: %s", res.Code, res.Message)
}
return nil
}
func (res *ResponseBody[RES]) GetData() *RES {
return &res.Details
}
type ResponseBody2[RES any] struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data RES `json:"data"`
}
func CommonResponse2[RES any]() client.ResponseBodyCheck {
return &ResponseBody2[RES]{}
}
func (res *ResponseBody2[RES]) CheckError() error {
if res.Code != 0 {
return fmt.Errorf("code: %d, msg: %s", res.Code, res.Msg)
}
return nil
}
func (res *ResponseBody2[RES]) GetData() *RES {
return &res.Data
}
type ResponseBody3[RES any] struct {
Status int `json:"status"`
Data RES `json:"data"`
Message string `json:"message"`
}
func CommonResponse3[RES any]() client.ResponseBodyCheck {
return &ResponseBody3[RES]{}
}
func (res *ResponseBody3[RES]) CheckError() error {
if res.Status != 0 {
return fmt.Errorf("status: %d, message: %s", res.Status, res.Message)
}
return nil
}