mirror of https://github.com/rocboss/paopao-ce
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
3.5 KiB
137 lines
3.5 KiB
// Code generated by go-mir. DO NOT EDIT.
|
|
|
|
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/alimy/mir/v3"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/rocboss/paopao-ce/internal/model/web"
|
|
)
|
|
|
|
type Loose interface {
|
|
// Chain provide handlers chain for gin
|
|
Chain() gin.HandlersChain
|
|
|
|
GetUserProfile() mir.Error
|
|
GetUserTweets() mir.Error
|
|
Timeline(*web.TimelineReq) (*web.TimelineResp, mir.Error)
|
|
|
|
mustEmbedUnimplementedLooseServant()
|
|
}
|
|
|
|
type LooseBinding interface {
|
|
BindTimeline(*gin.Context) (*web.TimelineReq, mir.Error)
|
|
|
|
mustEmbedUnimplementedLooseBinding()
|
|
}
|
|
|
|
type LooseRender interface {
|
|
RenderGetUserProfile(*gin.Context, mir.Error)
|
|
RenderGetUserTweets(*gin.Context, mir.Error)
|
|
RenderTimeline(*gin.Context, *web.TimelineResp, mir.Error)
|
|
|
|
mustEmbedUnimplementedLooseRender()
|
|
}
|
|
|
|
// RegisterLooseServant register Loose servant to gin
|
|
func RegisterLooseServant(e *gin.Engine, s Loose, b LooseBinding, r LooseRender) {
|
|
router := e.Group("v1")
|
|
// use chain for router
|
|
middlewares := s.Chain()
|
|
router.Use(middlewares...)
|
|
|
|
// register routes info to router
|
|
router.Handle("GET", "/user/profile", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
r.RenderGetUserProfile(c, s.GetUserProfile())
|
|
})
|
|
|
|
router.Handle("GET", "/user/posts", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
r.RenderGetUserTweets(c, s.GetUserTweets())
|
|
})
|
|
|
|
router.Handle("GET", "/posts", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
req, err := b.BindTimeline(c)
|
|
if err != nil {
|
|
r.RenderTimeline(c, nil, err)
|
|
return
|
|
}
|
|
resp, err := s.Timeline(req)
|
|
r.RenderTimeline(c, resp, err)
|
|
})
|
|
|
|
}
|
|
|
|
// UnimplementedLooseServant can be embedded to have forward compatible implementations.
|
|
type UnimplementedLooseServant struct {
|
|
}
|
|
|
|
func (UnimplementedLooseServant) Chain() gin.HandlersChain {
|
|
return nil
|
|
}
|
|
|
|
func (UnimplementedLooseServant) GetUserProfile() mir.Error {
|
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedLooseServant) GetUserTweets() mir.Error {
|
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedLooseServant) Timeline(req *web.TimelineReq) (*web.TimelineResp, mir.Error) {
|
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedLooseServant) mustEmbedUnimplementedLooseServant() {}
|
|
|
|
// UnimplementedLooseRender can be embedded to have forward compatible implementations.
|
|
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) RenderGetUserTweets(c *gin.Context, err mir.Error) {
|
|
r.RenderAny(c, nil, err)
|
|
}
|
|
|
|
func (r *UnimplementedLooseRender) RenderTimeline(c *gin.Context, data *web.TimelineResp, err mir.Error) {
|
|
r.RenderAny(c, data, err)
|
|
}
|
|
|
|
func (r *UnimplementedLooseRender) mustEmbedUnimplementedLooseRender() {}
|
|
|
|
// UnimplementedLooseBinding can be embedded to have forward compatible implementations.
|
|
type UnimplementedLooseBinding struct {
|
|
BindAny func(*gin.Context, any) mir.Error
|
|
}
|
|
|
|
func (b *UnimplementedLooseBinding) BindTimeline(c *gin.Context) (*web.TimelineReq, mir.Error) {
|
|
obj := new(web.TimelineReq)
|
|
err := b.BindAny(c, obj)
|
|
return obj, err
|
|
}
|
|
|
|
func (b *UnimplementedLooseBinding) mustEmbedUnimplementedLooseBinding() {}
|