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 {
- // fmt.Printf("get connect info from cache :%#v :", data)
- 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"})
- }
|