|
|
@ -16,6 +16,7 @@ type Loose interface {
|
|
|
|
// Chain provide handlers chain for gin
|
|
|
|
// Chain provide handlers chain for gin
|
|
|
|
Chain() gin.HandlersChain
|
|
|
|
Chain() gin.HandlersChain
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TweetComments(*web.TweetCommentsReq) (*web.TweetCommentsResp, mir.Error)
|
|
|
|
TopicList(*web.TopicListReq) (*web.TopicListResp, mir.Error)
|
|
|
|
TopicList(*web.TopicListReq) (*web.TopicListResp, mir.Error)
|
|
|
|
GetUserProfile(*web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error)
|
|
|
|
GetUserProfile(*web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error)
|
|
|
|
GetUserTweets(*web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error)
|
|
|
|
GetUserTweets(*web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error)
|
|
|
@ -25,6 +26,7 @@ type Loose interface {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type LooseBinding interface {
|
|
|
|
type LooseBinding interface {
|
|
|
|
|
|
|
|
BindTweetComments(*gin.Context) (*web.TweetCommentsReq, mir.Error)
|
|
|
|
BindTopicList(*gin.Context) (*web.TopicListReq, mir.Error)
|
|
|
|
BindTopicList(*gin.Context) (*web.TopicListReq, mir.Error)
|
|
|
|
BindGetUserProfile(*gin.Context) (*web.GetUserProfileReq, mir.Error)
|
|
|
|
BindGetUserProfile(*gin.Context) (*web.GetUserProfileReq, mir.Error)
|
|
|
|
BindGetUserTweets(*gin.Context) (*web.GetUserTweetsReq, mir.Error)
|
|
|
|
BindGetUserTweets(*gin.Context) (*web.GetUserTweetsReq, mir.Error)
|
|
|
@ -34,6 +36,7 @@ type LooseBinding interface {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type LooseRender interface {
|
|
|
|
type LooseRender interface {
|
|
|
|
|
|
|
|
RenderTweetComments(*gin.Context, *web.TweetCommentsResp, mir.Error)
|
|
|
|
RenderTopicList(*gin.Context, *web.TopicListResp, mir.Error)
|
|
|
|
RenderTopicList(*gin.Context, *web.TopicListResp, mir.Error)
|
|
|
|
RenderGetUserProfile(*gin.Context, *web.GetUserProfileResp, mir.Error)
|
|
|
|
RenderGetUserProfile(*gin.Context, *web.GetUserProfileResp, mir.Error)
|
|
|
|
RenderGetUserTweets(*gin.Context, *web.GetUserTweetsResp, mir.Error)
|
|
|
|
RenderGetUserTweets(*gin.Context, *web.GetUserTweetsResp, mir.Error)
|
|
|
@ -50,6 +53,22 @@ func RegisterLooseServant(e *gin.Engine, s Loose, b LooseBinding, r LooseRender)
|
|
|
|
router.Use(middlewares...)
|
|
|
|
router.Use(middlewares...)
|
|
|
|
|
|
|
|
|
|
|
|
// register routes info to router
|
|
|
|
// register routes info to router
|
|
|
|
|
|
|
|
router.Handle("GET", "/post/comments", func(c *gin.Context) {
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
|
|
|
case <-c.Request.Context().Done():
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
req, err := b.BindTweetComments(c)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
r.RenderTweetComments(c, nil, err)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.TweetComments(req)
|
|
|
|
|
|
|
|
r.RenderTweetComments(c, resp, err)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
router.Handle("GET", "/tags", func(c *gin.Context) {
|
|
|
|
router.Handle("GET", "/tags", func(c *gin.Context) {
|
|
|
|
select {
|
|
|
|
select {
|
|
|
|
case <-c.Request.Context().Done():
|
|
|
|
case <-c.Request.Context().Done():
|
|
|
@ -124,6 +143,10 @@ func (UnimplementedLooseServant) Chain() gin.HandlersChain {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (UnimplementedLooseServant) TweetComments(req *web.TweetCommentsReq) (*web.TweetCommentsResp, mir.Error) {
|
|
|
|
|
|
|
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (UnimplementedLooseServant) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Error) {
|
|
|
|
func (UnimplementedLooseServant) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Error) {
|
|
|
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
|
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -147,6 +170,10 @@ type UnimplementedLooseRender struct {
|
|
|
|
RenderAny func(*gin.Context, any, mir.Error)
|
|
|
|
RenderAny func(*gin.Context, any, mir.Error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (r *UnimplementedLooseRender) RenderTweetComments(c *gin.Context, data *web.TweetCommentsResp, err mir.Error) {
|
|
|
|
|
|
|
|
r.RenderAny(c, data, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r *UnimplementedLooseRender) RenderTopicList(c *gin.Context, data *web.TopicListResp, err mir.Error) {
|
|
|
|
func (r *UnimplementedLooseRender) RenderTopicList(c *gin.Context, data *web.TopicListResp, err mir.Error) {
|
|
|
|
r.RenderAny(c, data, err)
|
|
|
|
r.RenderAny(c, data, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -170,6 +197,12 @@ type UnimplementedLooseBinding struct {
|
|
|
|
BindAny func(*gin.Context, any) mir.Error
|
|
|
|
BindAny func(*gin.Context, any) mir.Error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (b *UnimplementedLooseBinding) BindTweetComments(c *gin.Context) (*web.TweetCommentsReq, mir.Error) {
|
|
|
|
|
|
|
|
obj := new(web.TweetCommentsReq)
|
|
|
|
|
|
|
|
err := b.BindAny(c, obj)
|
|
|
|
|
|
|
|
return obj, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b *UnimplementedLooseBinding) BindTopicList(c *gin.Context) (*web.TopicListReq, mir.Error) {
|
|
|
|
func (b *UnimplementedLooseBinding) BindTopicList(c *gin.Context) (*web.TopicListReq, mir.Error) {
|
|
|
|
obj := new(web.TopicListReq)
|
|
|
|
obj := new(web.TopicListReq)
|
|
|
|
err := b.BindAny(c, obj)
|
|
|
|
err := b.BindAny(c, obj)
|
|
|
|