mirror of https://github.com/rocboss/paopao-ce
commit
895aa90bc6
@ -1,24 +1,36 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rocboss/paopao-ce/internal/model"
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Comment = dbr.Comment
|
||||||
|
CommentFormated = dbr.CommentFormated
|
||||||
|
CommentReply = dbr.CommentReply
|
||||||
|
CommentContent = dbr.CommentContent
|
||||||
|
CommentReplyFormated = dbr.CommentReplyFormated
|
||||||
)
|
)
|
||||||
|
|
||||||
// CommentService 评论检索服务
|
// CommentService 评论检索服务
|
||||||
type CommentService interface {
|
type CommentService interface {
|
||||||
GetComments(conditions *model.ConditionsT, offset, limit int) ([]*model.Comment, error)
|
GetComments(conditions *ConditionsT, offset, limit int) ([]*Comment, error)
|
||||||
GetCommentByID(id int64) (*model.Comment, error)
|
GetCommentByID(id int64) (*Comment, error)
|
||||||
GetCommentCount(conditions *model.ConditionsT) (int64, error)
|
GetCommentCount(conditions *ConditionsT) (int64, error)
|
||||||
GetCommentReplyByID(id int64) (*model.CommentReply, error)
|
GetCommentReplyByID(id int64) (*CommentReply, error)
|
||||||
GetCommentContentsByIDs(ids []int64) ([]*model.CommentContent, error)
|
GetCommentContentsByIDs(ids []int64) ([]*CommentContent, error)
|
||||||
GetCommentRepliesByID(ids []int64) ([]*model.CommentReplyFormated, error)
|
GetCommentRepliesByID(ids []int64) ([]*CommentReplyFormated, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommentManageService 评论管理服务
|
// CommentManageService 评论管理服务
|
||||||
type CommentManageService interface {
|
type CommentManageService interface {
|
||||||
DeleteComment(comment *model.Comment) error
|
DeleteComment(comment *Comment) error
|
||||||
CreateComment(comment *model.Comment) (*model.Comment, error)
|
CreateComment(comment *Comment) (*Comment, error)
|
||||||
CreateCommentReply(reply *model.CommentReply) (*model.CommentReply, error)
|
CreateCommentReply(reply *CommentReply) (*CommentReply, error)
|
||||||
DeleteCommentReply(reply *model.CommentReply) error
|
DeleteCommentReply(reply *CommentReply) error
|
||||||
CreateCommentContent(content *model.CommentContent) (*model.CommentContent, error)
|
CreateCommentContent(content *CommentContent) (*CommentContent, error)
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,36 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rocboss/paopao-ce/internal/model"
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MsgTypePost = dbr.MsgTypePost
|
||||||
|
MsgtypeComment = dbr.MsgtypeComment
|
||||||
|
MsgTypeReply = dbr.MsgTypeReply
|
||||||
|
MsgTypeWhisper = dbr.MsgTypeWhisper
|
||||||
|
MsgTypeRequestingFriend = dbr.MsgTypeRequestingFriend
|
||||||
|
MsgTypeSystem = dbr.MsgTypeSystem
|
||||||
|
|
||||||
|
MsgStatusUnread = dbr.MsgStatusUnread
|
||||||
|
MsgStatusReaded = dbr.MsgStatusReaded
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Message = dbr.Message
|
||||||
|
MessageFormated = dbr.MessageFormated
|
||||||
)
|
)
|
||||||
|
|
||||||
// MessageService 消息服务
|
// MessageService 消息服务
|
||||||
type MessageService interface {
|
type MessageService interface {
|
||||||
CreateMessage(msg *model.Message) (*model.Message, error)
|
CreateMessage(msg *Message) (*Message, error)
|
||||||
GetUnreadCount(userID int64) (int64, error)
|
GetUnreadCount(userID int64) (int64, error)
|
||||||
GetMessageByID(id int64) (*model.Message, error)
|
GetMessageByID(id int64) (*Message, error)
|
||||||
ReadMessage(message *model.Message) error
|
ReadMessage(message *Message) error
|
||||||
GetMessages(conditions *model.ConditionsT, offset, limit int) ([]*model.MessageFormated, error)
|
GetMessages(conditions *ConditionsT, offset, limit int) ([]*MessageFormated, error)
|
||||||
GetMessageCount(conditions *model.ConditionsT) (int64, error)
|
GetMessageCount(conditions *ConditionsT) (int64, error)
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,22 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rocboss/paopao-ce/internal/model"
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Tag = dbr.Tag
|
||||||
|
TagFormated = dbr.TagFormated
|
||||||
)
|
)
|
||||||
|
|
||||||
// TopicService 话题服务
|
// TopicService 话题服务
|
||||||
type TopicService interface {
|
type TopicService interface {
|
||||||
CreateTag(tag *model.Tag) (*model.Tag, error)
|
CreateTag(tag *Tag) (*Tag, error)
|
||||||
DeleteTag(tag *model.Tag) error
|
DeleteTag(tag *Tag) error
|
||||||
GetTags(conditions *model.ConditionsT, offset, limit int) ([]*model.Tag, error)
|
GetTags(conditions *ConditionsT, offset, limit int) ([]*Tag, error)
|
||||||
GetTagsByKeyword(keyword string) ([]*model.Tag, error)
|
GetTagsByKeyword(keyword string) ([]*Tag, error)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
UserStatusNormal = dbr.UserStatusNormal
|
||||||
|
UserStatusClosed = dbr.UserStatusClosed
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
User = dbr.User
|
||||||
|
Post = dbr.Post
|
||||||
|
ConditionsT = dbr.ConditionsT
|
||||||
|
PostFormated = dbr.PostFormated
|
||||||
|
UserFormated = dbr.UserFormated
|
||||||
|
PostContentFormated = dbr.PostContentFormated
|
||||||
|
Model = dbr.Model
|
||||||
|
)
|
@ -1,15 +1,24 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rocboss/paopao-ce/internal/model"
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
WalletStatement = dbr.WalletStatement
|
||||||
|
WalletRecharge = dbr.WalletRecharge
|
||||||
)
|
)
|
||||||
|
|
||||||
// WalletService wallet service interface
|
// WalletService wallet service interface
|
||||||
type WalletService interface {
|
type WalletService interface {
|
||||||
GetUserWalletBills(userID int64, offset, limit int) ([]*model.WalletStatement, error)
|
GetUserWalletBills(userID int64, offset, limit int) ([]*WalletStatement, error)
|
||||||
GetUserWalletBillCount(userID int64) (int64, error)
|
GetUserWalletBillCount(userID int64) (int64, error)
|
||||||
GetRechargeByID(id int64) (*model.WalletRecharge, error)
|
GetRechargeByID(id int64) (*WalletRecharge, error)
|
||||||
CreateRecharge(userId, amount int64) (*model.WalletRecharge, error)
|
CreateRecharge(userId, amount int64) (*WalletRecharge, error)
|
||||||
HandleRechargeSuccess(recharge *model.WalletRecharge, tradeNo string) error
|
HandleRechargeSuccess(recharge *WalletRecharge, tradeNo string) error
|
||||||
HandlePostAttachmentBought(post *model.Post, user *model.User) error
|
HandlePostAttachmentBought(post *Post, user *User) error
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
type AttachmentType int
|
type AttachmentType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ATTACHMENT_TYPE_IMAGE AttachmentType = iota + 1
|
AttachmentTypeImage AttachmentType = iota + 1
|
||||||
ATTACHMENT_TYPE_VIDEO
|
AttachmentTypeVideo
|
||||||
ATTACHMENT_TYPE_OTHER
|
AttachmentTypeOther
|
||||||
)
|
)
|
||||||
|
|
||||||
type Attachment struct {
|
type Attachment struct {
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package model
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package dbr
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
### Mirc for paopao-ce
|
||||||
|
RESTful API for paopao-ce use [go-mir](https://github.com/alimy/mir) to generate service interface code automatic.
|
@ -0,0 +1,140 @@
|
|||||||
|
// 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 {
|
||||||
|
// Chain provide handlers chain for gin
|
||||||
|
Chain() gin.HandlersChain
|
||||||
|
|
||||||
|
Logout() mir.Error
|
||||||
|
Login(*LoginReq) (*LoginResp, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserServant()
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserBinding interface {
|
||||||
|
BindLogin(*gin.Context) (*LoginReq, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserBinding()
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserRender interface {
|
||||||
|
RenderLogout(*gin.Context, mir.Error)
|
||||||
|
RenderLogin(*gin.Context, *LoginResp, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserRender()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterUserServant register User servant to gin
|
||||||
|
func RegisterUserServant(e *gin.Engine, s User, b UserBinding, r UserRender) {
|
||||||
|
router := e.Group("m/v1")
|
||||||
|
// use chain for router
|
||||||
|
middlewares := s.Chain()
|
||||||
|
router.Use(middlewares...)
|
||||||
|
|
||||||
|
// register routes info to router
|
||||||
|
router.Handle("POST", "/user/logout/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
r.RenderLogout(c, s.Logout())
|
||||||
|
})
|
||||||
|
|
||||||
|
router.Handle("POST", "/user/login/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := b.BindLogin(c)
|
||||||
|
if err != nil {
|
||||||
|
r.RenderLogin(c, nil, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, err := s.Login(req)
|
||||||
|
r.RenderLogin(c, resp, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedUserServant can be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedUserServant struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedUserServant) Chain() gin.HandlersChain {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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) 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) 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() {}
|
@ -0,0 +1,140 @@
|
|||||||
|
// 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 {
|
||||||
|
// Chain provide handlers chain for gin
|
||||||
|
Chain() gin.HandlersChain
|
||||||
|
|
||||||
|
Logout() mir.Error
|
||||||
|
Login(*LoginReq) (*LoginResp, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserServant()
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserBinding interface {
|
||||||
|
BindLogin(*gin.Context) (*LoginReq, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserBinding()
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserRender interface {
|
||||||
|
RenderLogout(*gin.Context, mir.Error)
|
||||||
|
RenderLogin(*gin.Context, *LoginResp, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserRender()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterUserServant register User servant to gin
|
||||||
|
func RegisterUserServant(e *gin.Engine, s User, b UserBinding, r UserRender) {
|
||||||
|
router := e.Group("r/v1")
|
||||||
|
// use chain for router
|
||||||
|
middlewares := s.Chain()
|
||||||
|
router.Use(middlewares...)
|
||||||
|
|
||||||
|
// register routes info to router
|
||||||
|
router.Handle("POST", "/user/logout/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
r.RenderLogout(c, s.Logout())
|
||||||
|
})
|
||||||
|
|
||||||
|
router.Handle("POST", "/user/login/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := b.BindLogin(c)
|
||||||
|
if err != nil {
|
||||||
|
r.RenderLogin(c, nil, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, err := s.Login(req)
|
||||||
|
r.RenderLogin(c, resp, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedUserServant can be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedUserServant struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedUserServant) Chain() gin.HandlersChain {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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) 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) 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() {}
|
@ -0,0 +1,150 @@
|
|||||||
|
// 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 {
|
||||||
|
Logout() mir.Error
|
||||||
|
Login(*LoginReq) (*LoginResp, mir.Error)
|
||||||
|
Index() mir.Error
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserServant()
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserBinding interface {
|
||||||
|
BindLogin(*gin.Context) (*LoginReq, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserBinding()
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserRender interface {
|
||||||
|
RenderLogout(*gin.Context, mir.Error)
|
||||||
|
RenderLogin(*gin.Context, *LoginResp, mir.Error)
|
||||||
|
RenderIndex(*gin.Context, mir.Error)
|
||||||
|
|
||||||
|
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) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
r.RenderLogout(c, s.Logout())
|
||||||
|
})
|
||||||
|
|
||||||
|
router.Handle("POST", "/user/login/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := b.BindLogin(c)
|
||||||
|
if err != nil {
|
||||||
|
r.RenderLogin(c, nil, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, err := s.Login(req)
|
||||||
|
r.RenderLogin(c, resp, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
router.Handle("GET", "/index/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
r.RenderIndex(c, 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() {}
|
||||||
|
|
||||||
|
// 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() {}
|
@ -0,0 +1,184 @@
|
|||||||
|
// 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 WebCore interface {
|
||||||
|
// Chain provide handlers chain for gin
|
||||||
|
Chain() gin.HandlersChain
|
||||||
|
|
||||||
|
Logout() mir.Error
|
||||||
|
Login(*LoginReq) (*LoginResp, mir.Error)
|
||||||
|
Articles() mir.Error
|
||||||
|
Index() mir.Error
|
||||||
|
|
||||||
|
mustEmbedUnimplementedWebCoreServant()
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebCoreBinding interface {
|
||||||
|
BindLogin(*gin.Context) (*LoginReq, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedWebCoreBinding()
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebCoreRender interface {
|
||||||
|
RenderLogout(*gin.Context, mir.Error)
|
||||||
|
RenderLogin(*gin.Context, *LoginResp, mir.Error)
|
||||||
|
RenderArticles(*gin.Context, mir.Error)
|
||||||
|
RenderIndex(*gin.Context, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedWebCoreRender()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterWebCoreServant register WebCore servant to gin
|
||||||
|
func RegisterWebCoreServant(e *gin.Engine, s WebCore, b WebCoreBinding, r WebCoreRender) {
|
||||||
|
router := e.Group("v1")
|
||||||
|
// use chain for router
|
||||||
|
middlewares := s.Chain()
|
||||||
|
router.Use(middlewares...)
|
||||||
|
|
||||||
|
// register routes info to router
|
||||||
|
router.Handle("POST", "/user/logout/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
r.RenderLogout(c, s.Logout())
|
||||||
|
})
|
||||||
|
|
||||||
|
router.Handle("POST", "/user/login/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := b.BindLogin(c)
|
||||||
|
if err != nil {
|
||||||
|
r.RenderLogin(c, nil, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, err := s.Login(req)
|
||||||
|
r.RenderLogin(c, resp, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
{
|
||||||
|
h := func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
r.RenderArticles(c, s.Articles())
|
||||||
|
}
|
||||||
|
router.Handle("HEAD", "/articles/:category/", h)
|
||||||
|
router.Handle("GET", "/articles/:category/", h)
|
||||||
|
}
|
||||||
|
|
||||||
|
router.Handle("GET", "/index/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
r.RenderIndex(c, s.Index())
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedWebCoreServant can be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedWebCoreServant struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) Chain() gin.HandlersChain {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) Logout() mir.Error {
|
||||||
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) Login(req *LoginReq) (*LoginResp, mir.Error) {
|
||||||
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) Articles() mir.Error {
|
||||||
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) Index() mir.Error {
|
||||||
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedWebCoreServant) mustEmbedUnimplementedWebCoreServant() {}
|
||||||
|
|
||||||
|
// UnimplementedWebCoreRender can be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedWebCoreRender struct {
|
||||||
|
RenderAny func(*gin.Context, any, mir.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *UnimplementedWebCoreRender) RenderLogout(c *gin.Context, err mir.Error) {
|
||||||
|
r.RenderAny(c, nil, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *UnimplementedWebCoreRender) RenderLogin(c *gin.Context, data *LoginResp, err mir.Error) {
|
||||||
|
r.RenderAny(c, data, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *UnimplementedWebCoreRender) RenderArticles(c *gin.Context, err mir.Error) {
|
||||||
|
r.RenderAny(c, nil, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *UnimplementedWebCoreRender) RenderIndex(c *gin.Context, err mir.Error) {
|
||||||
|
r.RenderAny(c, nil, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *UnimplementedWebCoreRender) mustEmbedUnimplementedWebCoreRender() {}
|
||||||
|
|
||||||
|
// UnimplementedWebCoreBinding can be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedWebCoreBinding struct {
|
||||||
|
BindAny func(*gin.Context, any) mir.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *UnimplementedWebCoreBinding) BindLogin(c *gin.Context) (*LoginReq, mir.Error) {
|
||||||
|
obj := new(LoginReq)
|
||||||
|
err := b.BindAny(c, obj)
|
||||||
|
return obj, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *UnimplementedWebCoreBinding) mustEmbedUnimplementedWebCoreBinding() {}
|
@ -0,0 +1,140 @@
|
|||||||
|
// 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 {
|
||||||
|
// Chain provide handlers chain for gin
|
||||||
|
Chain() gin.HandlersChain
|
||||||
|
|
||||||
|
Logout() mir.Error
|
||||||
|
Login(*LoginReq) (*LoginResp, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserServant()
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserBinding interface {
|
||||||
|
BindLogin(*gin.Context) (*LoginReq, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserBinding()
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserRender interface {
|
||||||
|
RenderLogout(*gin.Context, mir.Error)
|
||||||
|
RenderLogin(*gin.Context, *LoginResp, mir.Error)
|
||||||
|
|
||||||
|
mustEmbedUnimplementedUserRender()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterUserServant register User servant to gin
|
||||||
|
func RegisterUserServant(e *gin.Engine, s User, b UserBinding, r UserRender) {
|
||||||
|
router := e.Group("x/v1")
|
||||||
|
// use chain for router
|
||||||
|
middlewares := s.Chain()
|
||||||
|
router.Use(middlewares...)
|
||||||
|
|
||||||
|
// register routes info to router
|
||||||
|
router.Handle("POST", "/user/logout/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
r.RenderLogout(c, s.Logout())
|
||||||
|
})
|
||||||
|
|
||||||
|
router.Handle("POST", "/user/login/", func(c *gin.Context) {
|
||||||
|
select {
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := b.BindLogin(c)
|
||||||
|
if err != nil {
|
||||||
|
r.RenderLogin(c, nil, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, err := s.Login(req)
|
||||||
|
r.RenderLogin(c, resp, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedUserServant can be embedded to have forward compatible implementations.
|
||||||
|
type UnimplementedUserServant struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UnimplementedUserServant) Chain() gin.HandlersChain {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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) 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) 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() {}
|
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2022 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
. "github.com/alimy/mir/v3/core"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
|
||||||
|
_ "github.com/rocboss/paopao-ce/internal/mirc/routes/admin/v1"
|
||||||
|
_ "github.com/rocboss/paopao-ce/internal/mirc/routes/bot/v1"
|
||||||
|
_ "github.com/rocboss/paopao-ce/internal/mirc/routes/localoss/v1"
|
||||||
|
_ "github.com/rocboss/paopao-ce/internal/mirc/routes/space/v1"
|
||||||
|
_ "github.com/rocboss/paopao-ce/internal/mirc/routes/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
func main() {
|
||||||
|
log.Println("generate code start")
|
||||||
|
opts := Options{
|
||||||
|
RunMode(InSerialDebugMode),
|
||||||
|
GeneratorName(GeneratorGin),
|
||||||
|
SinkPath("auto"),
|
||||||
|
}
|
||||||
|
if err := Generate(opts); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Println("generate code finish")
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
### RESTful API for paopao-ce
|
||||||
|
本目录包含所有RESTful API相关定义文件
|
||||||
|
|
||||||
|
|目录|系列API|备注|
|
||||||
|
| ----- | ----- | ----- |
|
||||||
|
|v1|/|Web v1版本RESTful API相关定义文件|
|
||||||
|
|admin|m|Admin后台运维系列相关RESTful API相关定义文件|
|
||||||
|
|space|x|SpaceX系列相关RESTful API相关定义文件|
|
||||||
|
|localoss|s| LocalOSS OBS系列RESTful API相关定义文件|
|
||||||
|
|bot|r| Bot系列相关RESTful API相关定义文件|
|
@ -0,0 +1,4 @@
|
|||||||
|
### Admin系列RESTful API相关定义文件
|
||||||
|
本目录包含 Admin后台运维相关API定义文件。
|
||||||
|
|
||||||
|
* v1 - v1版本API
|
@ -0,0 +1,42 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(User))
|
||||||
|
}
|
||||||
|
|
||||||
|
type AgentInfo struct {
|
||||||
|
Platform string `json:"platform"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerInfo struct {
|
||||||
|
ApiVer string `json:"api_ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserInfo struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginReq struct {
|
||||||
|
AgentInfo AgentInfo `json:"agent_info"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Passwd string `json:"passwd"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginResp struct {
|
||||||
|
UserInfo
|
||||||
|
ServerInfo ServerInfo `json:"server_info"`
|
||||||
|
JwtToken string `json:"jwt_token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"m/v1"`
|
||||||
|
Login func(Post, LoginReq) LoginResp `mir:"/user/login/"`
|
||||||
|
Logout func(Post) `mir:"/user/logout/"`
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
### Bot系列RESTful API相关定义文件
|
||||||
|
本目录包含 Bot相关API定义文件。
|
||||||
|
|
||||||
|
* v1 - v1版本API
|
@ -0,0 +1,42 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(User))
|
||||||
|
}
|
||||||
|
|
||||||
|
type AgentInfo struct {
|
||||||
|
Platform string `json:"platform"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerInfo struct {
|
||||||
|
ApiVer string `json:"api_ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserInfo struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginReq struct {
|
||||||
|
AgentInfo AgentInfo `json:"agent_info"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Passwd string `json:"passwd"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginResp struct {
|
||||||
|
UserInfo
|
||||||
|
ServerInfo ServerInfo `json:"server_info"`
|
||||||
|
JwtToken string `json:"jwt_token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"r/v1"`
|
||||||
|
Login func(Post, LoginReq) LoginResp `mir:"/user/login/"`
|
||||||
|
Logout func(Post) `mir:"/user/logout/"`
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
### LocalOSS OBS系列RESTful API相关定义文件
|
||||||
|
本目录包含 LocalOSS OBS 系列相关API定义文件。
|
||||||
|
|
||||||
|
* v1 - v1版本API
|
@ -0,0 +1,42 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(User))
|
||||||
|
}
|
||||||
|
|
||||||
|
type AgentInfo struct {
|
||||||
|
Platform string `json:"platform"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerInfo struct {
|
||||||
|
ApiVer string `json:"api_ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserInfo struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginReq struct {
|
||||||
|
AgentInfo AgentInfo `json:"agent_info"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Passwd string `json:"passwd"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginResp struct {
|
||||||
|
UserInfo
|
||||||
|
ServerInfo ServerInfo `json:"server_info"`
|
||||||
|
JwtToken string `json:"jwt_token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
Group Group `mir:"s/v1"`
|
||||||
|
Index func(Get) `mir:"/index/"`
|
||||||
|
Login func(Post, LoginReq) LoginResp `mir:"/user/login/"`
|
||||||
|
Logout func(Post) `mir:"/user/logout/"`
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
### SpaceX系列RESTful API
|
||||||
|
本目录包含SpaceX系列RESTful API相关定义文件
|
||||||
|
|
||||||
|
* v1 - v1版本API
|
@ -0,0 +1,42 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(User))
|
||||||
|
}
|
||||||
|
|
||||||
|
type AgentInfo struct {
|
||||||
|
Platform string `json:"platform"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerInfo struct {
|
||||||
|
ApiVer string `json:"api_ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserInfo struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginReq struct {
|
||||||
|
AgentInfo AgentInfo `json:"agent_info"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Passwd string `json:"passwd"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LoginResp struct {
|
||||||
|
UserInfo
|
||||||
|
ServerInfo ServerInfo `json:"server_info"`
|
||||||
|
JwtToken string `json:"jwt_token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"x/v1"`
|
||||||
|
Login func(Post, LoginReq) LoginResp `mir:"/user/login/"`
|
||||||
|
Logout func(Post) `mir:"/user/logout/"`
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(LocalOSS))
|
||||||
|
}
|
||||||
|
|
||||||
|
type LocalOSS struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/alimy/mir/v3"
|
||||||
|
. "github.com/alimy/mir/v3/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddEntry(new(WebAdmin))
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebAdmin struct {
|
||||||
|
Chain Chain `mir:"-"`
|
||||||
|
Group Group `mir:"v1"`
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue