12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package system
- import (
- "fmt"
- "io"
- "net/http"
- "xg_dba/api"
- "xg_dba/internal/global"
- system "xg_dba/internal/services/system"
- "github.com/gin-gonic/gin"
- )
- func GetSingleSystemInfo_controller(c *gin.Context) {
-
- connectInfo := api.ServerInfoRequest{}
- if err := c.BindJSON(&connectInfo); err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- return
- }
- if sysInfo, err := global.Cache.GetSingleSystemInfoCache(connectInfo.BaseFileName ,connectInfo.Host); err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- return
- } else {
- c.JSON(http.StatusOK, gin.H{"message": "success",
- "data": sysInfo,
- })
- }
- }
- func SetSystemInfo_controller(c *gin.Context) {
-
- connectInfo := []api.ServerInfoRequest{}
- if err := c.BindJSON(&connectInfo); err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- return
- }
- if connectInfo[0].BaseFileName == "" {
- c.JSON(http.StatusBadRequest, gin.H{"error": "BaseFileName is required"})
- return
- }
-
- progressID := global.Progress.CreateProgress()
-
- go func() {
- system.SetSystemInfo_service(connectInfo, fmt.Sprintf("./config/%s/", connectInfo[0].BaseFileName), progressID)
- }()
-
-
- c.JSON(http.StatusOK, gin.H{"message": "success",
- "progressID": progressID,
- })
-
-
-
-
-
-
-
-
-
- }
- func GetSystemInfoProgress_controller(c *gin.Context) {
-
- progressID := c.Query("progressID")
- if progressID == "" {
- c.JSON(400, gin.H{
- "error": "progressID is required",
- })
- return
- }
-
- progressChan, ok := global.Progress.GetProgressChan(progressID)
- if !ok {
- c.JSON(http.StatusNotFound, gin.H{"error": "Progress ID not found"})
- return
- }
-
- c.Stream(func(w io.Writer) bool {
- if message, ok := <-progressChan; ok {
- c.SSEvent("progress", gin.H{"message": message})
- fmt.Println("Progress给:", message)
- return true
- }
- return false
- })
- }
|