|
|
|
@ -14,22 +14,24 @@ type Loose interface {
|
|
|
|
|
// Chain provide handlers chain for gin
|
|
|
|
|
Chain() gin.HandlersChain
|
|
|
|
|
|
|
|
|
|
GetUserProfile() mir.Error
|
|
|
|
|
GetUserTweets() mir.Error
|
|
|
|
|
GetUserProfile(*web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error)
|
|
|
|
|
GetUserTweets(*web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error)
|
|
|
|
|
Timeline(*web.TimelineReq) (*web.TimelineResp, mir.Error)
|
|
|
|
|
|
|
|
|
|
mustEmbedUnimplementedLooseServant()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type LooseBinding interface {
|
|
|
|
|
BindGetUserProfile(*gin.Context) (*web.GetUserProfileReq, mir.Error)
|
|
|
|
|
BindGetUserTweets(*gin.Context) (*web.GetUserTweetsReq, mir.Error)
|
|
|
|
|
BindTimeline(*gin.Context) (*web.TimelineReq, mir.Error)
|
|
|
|
|
|
|
|
|
|
mustEmbedUnimplementedLooseBinding()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type LooseRender interface {
|
|
|
|
|
RenderGetUserProfile(*gin.Context, mir.Error)
|
|
|
|
|
RenderGetUserTweets(*gin.Context, mir.Error)
|
|
|
|
|
RenderGetUserProfile(*gin.Context, *web.GetUserProfileResp, mir.Error)
|
|
|
|
|
RenderGetUserTweets(*gin.Context, *web.GetUserTweetsResp, mir.Error)
|
|
|
|
|
RenderTimeline(*gin.Context, *web.TimelineResp, mir.Error)
|
|
|
|
|
|
|
|
|
|
mustEmbedUnimplementedLooseRender()
|
|
|
|
@ -50,7 +52,13 @@ func RegisterLooseServant(e *gin.Engine, s Loose, b LooseBinding, r LooseRender)
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r.RenderGetUserProfile(c, s.GetUserProfile())
|
|
|
|
|
req, err := b.BindGetUserProfile(c)
|
|
|
|
|
if err != nil {
|
|
|
|
|
r.RenderGetUserProfile(c, nil, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp, err := s.GetUserProfile(req)
|
|
|
|
|
r.RenderGetUserProfile(c, resp, err)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.Handle("GET", "/user/posts", func(c *gin.Context) {
|
|
|
|
@ -60,7 +68,13 @@ func RegisterLooseServant(e *gin.Engine, s Loose, b LooseBinding, r LooseRender)
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r.RenderGetUserTweets(c, s.GetUserTweets())
|
|
|
|
|
req, err := b.BindGetUserTweets(c)
|
|
|
|
|
if err != nil {
|
|
|
|
|
r.RenderGetUserTweets(c, nil, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp, err := s.GetUserTweets(req)
|
|
|
|
|
r.RenderGetUserTweets(c, resp, err)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.Handle("GET", "/posts", func(c *gin.Context) {
|
|
|
|
@ -89,12 +103,12 @@ func (UnimplementedLooseServant) Chain() gin.HandlersChain {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (UnimplementedLooseServant) GetUserProfile() mir.Error {
|
|
|
|
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
|
|
|
func (UnimplementedLooseServant) GetUserProfile(req *web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error) {
|
|
|
|
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (UnimplementedLooseServant) GetUserTweets() mir.Error {
|
|
|
|
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
|
|
|
func (UnimplementedLooseServant) GetUserTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) {
|
|
|
|
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (UnimplementedLooseServant) Timeline(req *web.TimelineReq) (*web.TimelineResp, mir.Error) {
|
|
|
|
@ -108,12 +122,12 @@ type UnimplementedLooseRender struct {
|
|
|
|
|
RenderAny func(*gin.Context, any, mir.Error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *UnimplementedLooseRender) RenderGetUserProfile(c *gin.Context, err mir.Error) {
|
|
|
|
|
r.RenderAny(c, nil, err)
|
|
|
|
|
func (r *UnimplementedLooseRender) RenderGetUserProfile(c *gin.Context, data *web.GetUserProfileResp, err mir.Error) {
|
|
|
|
|
r.RenderAny(c, data, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *UnimplementedLooseRender) RenderGetUserTweets(c *gin.Context, err mir.Error) {
|
|
|
|
|
r.RenderAny(c, nil, err)
|
|
|
|
|
func (r *UnimplementedLooseRender) RenderGetUserTweets(c *gin.Context, data *web.GetUserTweetsResp, err mir.Error) {
|
|
|
|
|
r.RenderAny(c, data, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *UnimplementedLooseRender) RenderTimeline(c *gin.Context, data *web.TimelineResp, err mir.Error) {
|
|
|
|
@ -127,6 +141,18 @@ type UnimplementedLooseBinding struct {
|
|
|
|
|
BindAny func(*gin.Context, any) mir.Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *UnimplementedLooseBinding) BindGetUserProfile(c *gin.Context) (*web.GetUserProfileReq, mir.Error) {
|
|
|
|
|
obj := new(web.GetUserProfileReq)
|
|
|
|
|
err := b.BindAny(c, obj)
|
|
|
|
|
return obj, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *UnimplementedLooseBinding) BindGetUserTweets(c *gin.Context) (*web.GetUserTweetsReq, mir.Error) {
|
|
|
|
|
obj := new(web.GetUserTweetsReq)
|
|
|
|
|
err := b.BindAny(c, obj)
|
|
|
|
|
return obj, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *UnimplementedLooseBinding) BindTimeline(c *gin.Context) (*web.TimelineReq, mir.Error) {
|
|
|
|
|
obj := new(web.TimelineReq)
|
|
|
|
|
err := b.BindAny(c, obj)
|
|
|
|
|