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.
136 lines
2.7 KiB
136 lines
2.7 KiB
// Code generated by go-mir. DO NOT EDIT.
|
|
// versions:
|
|
// - mir v4.0.0
|
|
|
|
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/alimy/mir/v4"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type _binding_ interface {
|
|
Bind(*gin.Context) mir.Error
|
|
}
|
|
|
|
type _render_ interface {
|
|
Render(*gin.Context)
|
|
}
|
|
|
|
type _default_ interface {
|
|
Bind(*gin.Context, any) mir.Error
|
|
Render(*gin.Context, any, mir.Error)
|
|
}
|
|
|
|
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 {
|
|
_default_
|
|
|
|
Logout() mir.Error
|
|
Login(*LoginReq) (*LoginResp, mir.Error)
|
|
Index() mir.Error
|
|
|
|
mustEmbedUnimplementedUserServant()
|
|
}
|
|
|
|
// RegisterUserServant register User servant to gin
|
|
func RegisterUserServant(e *gin.Engine, s User) {
|
|
router := e.Group("s/v1")
|
|
|
|
// register routes info to router
|
|
router.Handle("POST", "/user/logout/", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
s.Render(c, nil, s.Logout())
|
|
})
|
|
router.Handle("POST", "/user/login/", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
var (
|
|
obj any
|
|
err mir.Error
|
|
)
|
|
req := new(LoginReq)
|
|
obj = req
|
|
if bv, ok := obj.(_binding_); !ok {
|
|
err = s.Bind(c, req)
|
|
} else {
|
|
err = bv.Bind(c)
|
|
}
|
|
if err != nil {
|
|
s.Render(c, nil, err)
|
|
return
|
|
}
|
|
obj, err = s.Login(req)
|
|
if err != nil {
|
|
s.Render(c, nil, err)
|
|
return
|
|
}
|
|
if rv, ok := obj.(_render_); !ok {
|
|
s.Render(c, obj, nil)
|
|
} else {
|
|
rv.Render(c)
|
|
}
|
|
})
|
|
router.Handle("GET", "/index/", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
s.Render(c, nil, s.Index())
|
|
})
|
|
}
|
|
|
|
// UnimplementedUserServant can be embedded to have forward compatible implementations.
|
|
type UnimplementedUserServant struct{}
|
|
|
|
func (UnimplementedUserServant) Logout() mir.Error {
|
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedUserServant) Login(req *LoginReq) (*LoginResp, mir.Error) {
|
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedUserServant) Index() mir.Error {
|
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedUserServant) mustEmbedUnimplementedUserServant() {}
|