first commit

This commit is contained in:
2022-03-17 15:59:24 +08:00
commit 2b0debb847
592 changed files with 73946 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package http
import (
"github.com/gin-gonic/gin"
"gitlab.33.cn/chat/dtalk/pkg/api"
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
"gitlab.33.cn/chat/dtalk/pkg/util"
"gitlab.33.cn/chat/dtalk/service/call/model"
)
// checkCall
// @Summary 检查通话状态
// @Author chy@33.cn
// @Tags call
// @Param FZM-SIGNATURE header string true "MOCK"
// @Param data body model.CheckCallRequest false "body"
// @Success 200 {object} model.GeneralResponse{data=model.CheckCallResponse}
// @Router /app/check-call [post]
func checkCall(c *gin.Context) {
userId, ok := c.Get(api.Address)
if !ok {
c.Set(api.ReqError, xerror.NewError(xerror.SignatureInvalid))
return
}
req := &model.CheckCallRequest{}
err := c.ShouldBind(req)
if err != nil {
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage(err.Error()))
return
}
if req.TraceId == 0 && req.TraceIdStr == "" {
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError))
return
}
if req.TraceIdStr != "" {
traceId, err := util.ToInt64E(req.TraceIdStr)
if err != nil {
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage(err.Error()))
return
}
req.TraceId = traceId
}
req.PersonId = userId.(string)
res, err := svc.CheckCall(req)
c.Set(api.ReqResult, res)
c.Set(api.ReqError, err)
}

View File

@@ -0,0 +1,52 @@
package http
import (
"github.com/gin-gonic/gin"
"gitlab.33.cn/chat/dtalk/pkg/api"
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
"gitlab.33.cn/chat/dtalk/pkg/util"
"gitlab.33.cn/chat/dtalk/service/call/model"
)
// handleCall
// @Summary 处理通话
// @Author chy@33.cn
// @Tags call
// @Param FZM-SIGNATURE header string true "MOCK"
// @Param data body model.HandleCallRequest false "body"
// @Success 200 {object} model.GeneralResponse{data=model.HandleCallResponse}
// @Router /app/handle-call [post]
func handleCall(c *gin.Context) {
userId, ok := c.Get(api.Address)
if !ok {
c.Set(api.ReqError, xerror.NewError(xerror.SignatureInvalid))
return
}
req := &model.HandleCallRequest{}
err := c.ShouldBind(req)
if err != nil {
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage(err.Error()))
return
}
if req.TraceId == 0 && req.TraceIdStr == "" {
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError))
return
}
if req.TraceIdStr != "" {
traceId, err := util.ToInt64E(req.TraceIdStr)
if err != nil {
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage(err.Error()))
return
}
req.TraceId = traceId
}
req.PersonId = userId.(string)
res, err := svc.HandleCall(req)
c.Set(api.ReqResult, res)
c.Set(api.ReqError, err)
}

View File

@@ -0,0 +1,73 @@
package http
import (
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"gitlab.33.cn/chat/dtalk/pkg/api"
"gitlab.33.cn/chat/dtalk/pkg/logger"
"gitlab.33.cn/chat/dtalk/service/call/service"
"net/http"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
_ "gitlab.33.cn/chat/dtalk/service/call/docs"
)
const srvName = "call/http"
var (
svc *service.Service
log zerolog.Logger
)
func Init(s *service.Service) *http.Server {
addr := s.Config().HttpServer.Addr
engine := defaultEngine()
initService(s)
setupEngine(engine)
log = logger.New(s.Config().Env, srvName)
srv := &http.Server{
Addr: addr,
Handler: engine,
}
go func() {
// service connections
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Error().Err(err).Msg("engineInner.Start()")
panic(err)
}
}()
return srv
}
// defaultEngine returns an Engine instance with the Logger and Recovery middleware already attached.
func defaultEngine() *gin.Engine {
router := gin.New()
// LoggerWithFormatter middleware will write the logs to gin.DefaultWriter
// By default gin.DefaultWriter = os.Stdout
router.Use(gin.LoggerWithFormatter(api.Chat33GinLogFormatter))
router.Use(gin.Recovery())
return router
}
func initService(s *service.Service) {
svc = s
}
// setupEngine
// @title 音视频信令服务接口
// @version 1.0
// @host 127.0.0.1:18013
func setupEngine(e *gin.Engine) *gin.Engine {
app := e.Group("/app", api.RespMiddleWare(), api.AuthMiddleWare())
{
app.POST("/start-call", startCall)
app.POST("/reply-busy", replyBusy)
app.POST("/check-call", checkCall)
app.POST("/handle-call", handleCall)
}
e.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
return e
}

View File

@@ -0,0 +1,52 @@
package http
import (
"github.com/gin-gonic/gin"
"gitlab.33.cn/chat/dtalk/pkg/api"
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
"gitlab.33.cn/chat/dtalk/pkg/util"
"gitlab.33.cn/chat/dtalk/service/call/model"
)
// replyBusy
// @Summary 返回忙碌
// @Author chy@33.cn
// @Tags call
// @Param FZM-SIGNATURE header string true "MOCK"
// @Param data body model.ReplyBusyRequest false "body"
// @Success 200 {object} model.GeneralResponse{data=model.ReplyBusyResponse}
// @Router /app/reply-busy [post]
func replyBusy(c *gin.Context) {
userId, ok := c.Get(api.Address)
if !ok {
c.Set(api.ReqError, xerror.NewError(xerror.SignatureInvalid))
return
}
req := &model.ReplyBusyRequest{}
err := c.ShouldBind(req)
if err != nil {
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage(err.Error()))
return
}
if req.TraceId == 0 && req.TraceIdStr == "" {
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError))
return
}
if req.TraceIdStr != "" {
traceId, err := util.ToInt64E(req.TraceIdStr)
if err != nil {
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage(err.Error()))
return
}
req.TraceId = traceId
}
req.PersonId = userId.(string)
res, err := svc.ReplyBusy(req)
c.Set(api.ReqResult, res)
c.Set(api.ReqError, err)
}

View File

@@ -0,0 +1,37 @@
package http
import (
"github.com/gin-gonic/gin"
"gitlab.33.cn/chat/dtalk/pkg/api"
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
"gitlab.33.cn/chat/dtalk/service/call/model"
)
// startCall
// @Summary 开始通话
// @Author chy@33.cn
// @Tags call
// @Param FZM-SIGNATURE header string true "MOCK"
// @Param data body model.StartCallRequest false "body"
// @Success 200 {object} model.GeneralResponse{data=model.StartCallResponse}
// @Router /app/start-call [post]
func startCall(c *gin.Context) {
userId, ok := c.Get(api.Address)
if !ok {
c.Set(api.ReqError, xerror.NewError(xerror.SignatureInvalid))
return
}
req := &model.StartCallRequest{}
err := c.ShouldBind(req)
if err != nil {
c.Set(api.ReqError, xerror.NewError(xerror.ParamsError).SetExtMessage(err.Error()))
return
}
req.PersonId = userId.(string)
res, err := svc.StartCall(req)
c.Set(api.ReqResult, res)
c.Set(api.ReqError, err)
}