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.
151 lines
3.5 KiB
151 lines
3.5 KiB
2 years ago
|
// Code generated by go-mir. DO NOT EDIT.
|
||
|
|
||
|
package v1
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/alimy/mir/v3"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
type LoginReq struct {
|
||
|
AgentInfo AgentInfo `json:"agent_info"`
|
||
|
Name string `json:"name"`
|
||
|
Passwd string `json:"passwd"`
|
||
|
}
|
||
|
|
||
|
type AgentInfo struct {
|
||
|
Platform string `json:"platform"`
|
||
|
UserAgent string `json:"user_agent"`
|
||
|
}
|
||
|
|
||
|
type LoginResp struct {
|
||
|
UserInfo
|
||
|
ServerInfo ServerInfo `json:"server_info"`
|
||
|
JwtToken string `json:"jwt_token"`
|
||
|
}
|
||
|
|
||
|
type ServerInfo struct {
|
||
|
ApiVer string `json:"api_ver"`
|
||
|
}
|
||
|
|
||
|
type UserInfo struct {
|
||
|
Name string `json:"name"`
|
||
|
}
|
||
|
|
||
|
type User interface {
|
||
2 years ago
|
Logout() mir.Error
|
||
|
Login(*LoginReq) (*LoginResp, mir.Error)
|
||
|
Index() mir.Error
|
||
2 years ago
|
|
||
|
mustEmbedUnimplementedUserServant()
|
||
|
}
|
||
|
|
||
|
type UserBinding interface {
|
||
2 years ago
|
BindLogin(*gin.Context) (*LoginReq, mir.Error)
|
||
2 years ago
|
|
||
|
mustEmbedUnimplementedUserBinding()
|
||
|
}
|
||
|
|
||
|
type UserRender interface {
|
||
2 years ago
|
RenderLogout(*gin.Context, mir.Error)
|
||
|
RenderLogin(*gin.Context, *LoginResp, mir.Error)
|
||
|
RenderIndex(*gin.Context, mir.Error)
|
||
2 years ago
|
|
||
|
mustEmbedUnimplementedUserRender()
|
||
|
}
|
||
|
|
||
|
// RegisterUserServant register User servant to gin
|
||
|
func RegisterUserServant(e *gin.Engine, s User, b UserBinding, r UserRender) {
|
||
|
router := e.Group("s/v1")
|
||
|
|
||
|
// register routes info to router
|
||
|
router.Handle("POST", "/user/logout/", func(c *gin.Context) {
|
||
2 years ago
|
select {
|
||
|
case <-c.Request.Context().Done():
|
||
|
return
|
||
|
default:
|
||
|
}
|
||
|
|
||
2 years ago
|
r.RenderLogout(c, s.Logout())
|
||
2 years ago
|
})
|
||
|
|
||
|
router.Handle("POST", "/user/login/", func(c *gin.Context) {
|
||
2 years ago
|
select {
|
||
|
case <-c.Request.Context().Done():
|
||
|
return
|
||
|
default:
|
||
|
}
|
||
|
|
||
2 years ago
|
req, err := b.BindLogin(c)
|
||
|
if err != nil {
|
||
|
r.RenderLogin(c, nil, err)
|
||
2 years ago
|
return
|
||
2 years ago
|
}
|
||
2 years ago
|
resp, err := s.Login(req)
|
||
2 years ago
|
r.RenderLogin(c, resp, err)
|
||
|
})
|
||
|
|
||
|
router.Handle("GET", "/index/", func(c *gin.Context) {
|
||
2 years ago
|
select {
|
||
|
case <-c.Request.Context().Done():
|
||
|
return
|
||
|
default:
|
||
|
}
|
||
|
|
||
2 years ago
|
r.RenderIndex(c, s.Index())
|
||
2 years ago
|
})
|
||
|
|
||
|
}
|
||
|
|
||
|
// UnimplementedUserServant can be embedded to have forward compatible implementations.
|
||
|
type UnimplementedUserServant struct {
|
||
|
}
|
||
|
|
||
2 years ago
|
func (UnimplementedUserServant) Logout() mir.Error {
|
||
2 years ago
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||
|
}
|
||
|
|
||
2 years ago
|
func (UnimplementedUserServant) Login(req *LoginReq) (*LoginResp, mir.Error) {
|
||
2 years ago
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||
|
}
|
||
|
|
||
2 years ago
|
func (UnimplementedUserServant) Index() mir.Error {
|
||
2 years ago
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||
|
}
|
||
|
|
||
|
func (UnimplementedUserServant) mustEmbedUnimplementedUserServant() {}
|
||
|
|
||
|
// UnimplementedUserRender can be embedded to have forward compatible implementations.
|
||
|
type UnimplementedUserRender struct {
|
||
|
RenderAny func(*gin.Context, any, mir.Error)
|
||
|
}
|
||
|
|
||
|
func (r *UnimplementedUserRender) RenderLogout(c *gin.Context, err mir.Error) {
|
||
|
r.RenderAny(c, nil, err)
|
||
|
}
|
||
|
|
||
|
func (r *UnimplementedUserRender) RenderLogin(c *gin.Context, data *LoginResp, err mir.Error) {
|
||
|
r.RenderAny(c, data, err)
|
||
|
}
|
||
|
|
||
|
func (r *UnimplementedUserRender) RenderIndex(c *gin.Context, err mir.Error) {
|
||
|
r.RenderAny(c, nil, err)
|
||
|
}
|
||
|
|
||
|
func (r *UnimplementedUserRender) mustEmbedUnimplementedUserRender() {}
|
||
|
|
||
|
// UnimplementedUserBinding can be embedded to have forward compatible implementations.
|
||
|
type UnimplementedUserBinding struct {
|
||
|
BindAny func(*gin.Context, any) mir.Error
|
||
|
}
|
||
|
|
||
|
func (b *UnimplementedUserBinding) BindLogin(c *gin.Context) (*LoginReq, mir.Error) {
|
||
|
obj := new(LoginReq)
|
||
|
err := b.BindAny(c, obj)
|
||
|
return obj, err
|
||
|
}
|
||
|
|
||
|
func (b *UnimplementedUserBinding) mustEmbedUnimplementedUserBinding() {}
|