-
Notifications
You must be signed in to change notification settings - Fork 0
/
resp.go
76 lines (69 loc) · 2.07 KB
/
resp.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
74
75
76
package pack
import (
"errors"
"github.com/xiaohei366/TinyTiktok/kitex_gen/VideoServer"
"github.com/xiaohei366/TinyTiktok/pkg/errno"
)
func BuildFeedResp(err error, videoList []*VideoServer.Video, nextTime int64) *VideoServer.DouyinFeedResponse {
if err == nil {
return feedResp(errno.Success, videoList, nextTime)
}
e := errno.ErrNo{}
if errors.As(err, &e) {
return feedResp(e, videoList, nextTime)
}
s := errno.ServiceErr.WithMessage(err.Error())
return feedResp(s, videoList, nextTime)
}
// 封装feed返回
func feedResp(err errno.ErrNo, videoList []*VideoServer.Video, nextTime int64) *VideoServer.DouyinFeedResponse {
resp := new(VideoServer.DouyinFeedResponse)
resp.BaseResp = &VideoServer.BaseResp{
StatusCode: err.ErrCode,
StatusMsg: err.ErrMsg,
}
resp.VideoList = videoList
resp.NextTime = nextTime
return resp
}
// 封装发布视频操作
func BuildPublishActionResp(err error) *VideoServer.DouyinPublishActionResponse {
if err == nil {
return publishActionResp(errno.Success)
}
e := errno.ErrNo{}
if errors.As(err, &e) {
return publishActionResp(e)
}
s := errno.ServiceErr.WithMessage(err.Error())
return publishActionResp(s)
}
func publishActionResp(err errno.ErrNo) *VideoServer.DouyinPublishActionResponse {
resp := new(VideoServer.DouyinPublishActionResponse)
resp.BaseResp = &VideoServer.BaseResp{
StatusCode: err.ErrCode,
StatusMsg: err.ErrMsg,
}
return resp
}
// 封装视频列表返回报文
func BuildPublishListResp(err error, videoList []*VideoServer.Video) *VideoServer.DouyinPublishListResponse {
if err == nil {
return publishListResp(errno.Success, videoList)
}
e := errno.ErrNo{}
if errors.As(err, &e) {
return publishListResp(e, videoList)
}
s := errno.ServiceErr.WithMessage(err.Error())
return publishListResp(s, videoList)
}
func publishListResp(err errno.ErrNo, videoList []*VideoServer.Video) *VideoServer.DouyinPublishListResponse {
resp := new(VideoServer.DouyinPublishListResponse)
resp.BaseResp = &VideoServer.BaseResp{
StatusCode: err.ErrCode,
StatusMsg: err.ErrMsg,
}
resp.VideoList = videoList
return resp
}