版本封存
This commit is contained in:
@@ -2,10 +2,10 @@ package controllers
|
||||
|
||||
import (
|
||||
models2 "cmii-uav-watchdog-common/models"
|
||||
"cmii-uav-watchdog/models"
|
||||
"cmii-uav-watchdog-common/wdd_log"
|
||||
"cmii-uav-watchdog/services"
|
||||
"net/http"
|
||||
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -26,59 +26,52 @@ func (ac *AuthController) GenerateAuthFile(c *gin.Context) {
|
||||
// 生成授权文件
|
||||
authFile, err := ac.authService.GenerateAuthorizationFile()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.Response{
|
||||
Code: 500,
|
||||
Message: "生成授权文件失败",
|
||||
Data: nil,
|
||||
})
|
||||
c.JSON(http.StatusInternalServerError, authFile)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, models.Response{
|
||||
Code: 200,
|
||||
Message: "生成授权文件成功",
|
||||
Data: authFile,
|
||||
})
|
||||
|
||||
c.JSON(http.StatusOK, authFile)
|
||||
}
|
||||
|
||||
// ReceiveAuthCode 接收授权码
|
||||
func (ac *AuthController) ReceiveAuthCode(c *gin.Context) {
|
||||
var authCode models2.AuthorizationCode
|
||||
if err := c.ShouldBindJSON(&authCode); err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.Response{
|
||||
Code: 400,
|
||||
Message: "无效的请求参数",
|
||||
Data: nil,
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, authCode)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// 处理授权码
|
||||
err := ac.authService.ProcessAuthorizationCode(authCode)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.Response{
|
||||
Code: 500,
|
||||
Message: "处理授权码失败: " + err.Error(),
|
||||
Data: nil,
|
||||
})
|
||||
wdd_log.Error("处理授权码失败: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, authCode)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, models.Response{
|
||||
Code: 200,
|
||||
Message: "处理授权码成功",
|
||||
Data: nil,
|
||||
})
|
||||
|
||||
c.JSON(http.StatusOK, authCode)
|
||||
}
|
||||
|
||||
// NotifyAuthInfo 通知授权信息
|
||||
func (ac *AuthController) NotifyAuthInfo(c *gin.Context) {
|
||||
// 获取授权信息
|
||||
authInfo := ac.authService.GetAuthorizationInfo()
|
||||
|
||||
c.JSON(http.StatusOK, models.Response{
|
||||
Code: 200,
|
||||
Message: "获取授权信息成功",
|
||||
Data: authInfo,
|
||||
authInfo, err := ac.authService.GetAuthorizationInfo()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, authInfo)
|
||||
}
|
||||
|
||||
// GetAllAuthorizedHosts 获取所有已授权的主机信息
|
||||
func (ac *AuthController) GetAllAuthorizedHosts(c *gin.Context) {
|
||||
// 获取所有已授权的主机信息
|
||||
authorizedHosts := ac.authService.GetAllAuthorizedHosts()
|
||||
|
||||
// 返回已授权主机信息
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"authorized_host_count": len(authorizedHosts),
|
||||
"authorized_hosts": authorizedHosts,
|
||||
})
|
||||
}
|
||||
|
||||
24
cmii-uav-watchdog/controllers/cmii_controller.go
Normal file
24
cmii-uav-watchdog/controllers/cmii_controller.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"cmii-uav-watchdog/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// CMIIController CMII控制器
|
||||
type CMIIController struct {
|
||||
cmiiService *services.CMIIService
|
||||
}
|
||||
|
||||
// NewCMIIController 创建CMII控制器
|
||||
func NewCMIIController() *CMIIController {
|
||||
return &CMIIController{
|
||||
cmiiService: services.NewCMIIService(),
|
||||
}
|
||||
}
|
||||
|
||||
// HandleHostInfo 处理主机信息
|
||||
func (cc *CMIIController) HandleHostInfo(c *gin.Context) {
|
||||
cc.cmiiService.HandleHostInfo(c)
|
||||
}
|
||||
@@ -2,10 +2,10 @@ package controllers
|
||||
|
||||
import (
|
||||
models2 "cmii-uav-watchdog-common/models"
|
||||
"cmii-uav-watchdog/models"
|
||||
"cmii-uav-watchdog-common/wdd_log"
|
||||
"cmii-uav-watchdog/services"
|
||||
"net/http"
|
||||
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -25,28 +25,36 @@ func NewHeartbeatController() *HeartbeatController {
|
||||
func (hc *HeartbeatController) HandleHeartbeat(c *gin.Context) {
|
||||
var req models2.HeartbeatRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.Response{
|
||||
Code: 400,
|
||||
Message: "无效的请求参数",
|
||||
Data: nil,
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, req)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// 处理心跳
|
||||
resp, err := hc.heartbeatService.ProcessHeartbeat(req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.Response{
|
||||
Code: 500,
|
||||
Message: "处理心跳失败: " + err.Error(),
|
||||
Data: nil,
|
||||
c.JSON(http.StatusInternalServerError, resp)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetAllHeartbeatHosts 获取所有心跳主机信息
|
||||
func (hc *HeartbeatController) GetAllHeartbeatHosts(c *gin.Context) {
|
||||
// 获取所有主机信息
|
||||
hostInfoMap, err := hc.heartbeatService.GetAllHostInfo()
|
||||
if err != nil {
|
||||
wdd_log.Error("获取所有心跳主机信息失败: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "获取所有心跳主机信息失败",
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, models.Response{
|
||||
Code: 200,
|
||||
Message: "处理心跳成功",
|
||||
Data: resp,
|
||||
|
||||
// 返回主机信息
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"host_count": len(hostInfoMap),
|
||||
"hosts": hostInfoMap,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user