12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package connect
- import (
- "net/http"
- "xg_dba/api"
- "xg_dba/internal/global"
- services "xg_dba/internal/services/connect"
- "github.com/gin-gonic/gin"
- )
- func GetConnectInfo_controller(c *gin.Context) {
- if data, err := global.Cache.GetConnectCache(); err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- return
- } else {
-
- c.JSON(http.StatusOK, gin.H{"message": "success",
- "data": data,
- })
- }
- }
- func AddConnectInfo_controller(c *gin.Context) {
- connectInfo := []api.ConnectInfoRequest{}
- if err := c.BindJSON(&connectInfo); err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- return
- }
-
- if connectInfo[0].Ssh.Host == "" {
- c.JSON(http.StatusBadRequest, gin.H{"error": "host不能为空"})
- return
- }
-
- localPath := "./config/" + connectInfo[0].Ssh.Host + "/" + "listen" + ".toml"
- if err := services.SetConnectInfo_service(connectInfo, localPath); err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- return
- }
- c.JSON(http.StatusOK, gin.H{"message": "success"})
- }
|