connect.go 664 B

12345678910111213141516171819202122232425
  1. package connect
  2. import (
  3. "net/http"
  4. "xg_dba/api"
  5. services "xg_dba/internal/services/connect"
  6. "github.com/gin-gonic/gin"
  7. )
  8. // 获取连接信息
  9. func SaveConnectInfo_controller(c *gin.Context) {
  10. connectInfo := api.ConnectInfoRequest{}
  11. if err := c.BindJSON(&connectInfo); err != nil {
  12. c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
  13. return
  14. }
  15. //存储到本地
  16. localPath := "./config/" + connectInfo.Ssh.Host + "/" + connectInfo.Ssh.Host + ".toml"
  17. if err := services.SetConnectInfo_service(connectInfo, localPath); err != nil {
  18. c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
  19. return
  20. }
  21. c.JSON(http.StatusOK, connectInfo)
  22. }