-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
44 lines (36 loc) · 902 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 client
import (
"fmt"
"github.com/hopeio/cherry/utils/net/http/client"
)
type ResponseBody[RES any] struct {
Status int `json:"status"`
Data RES `json:"data"`
Message string `json:"message"`
}
func CommonResponse[RES any]() client.ResponseBodyCheck {
return &ResponseBody[RES]{}
}
func (res *ResponseBody[RES]) CheckError() error {
if res.Status != 0 {
return fmt.Errorf("status: %d, message: %s", res.Status, res.Message)
}
return nil
}
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
}