func Connect(c *gin.Context) { if command.Opts.LockSession { c.JSON(400, Error{"Session is locked"}) return } var sshInfo *shared.SSHInfo url := c.Request.FormValue("url") if url == "" { c.JSON(400, Error{"Url parameter is required"}) return } opts := command.Options{Url: url} url, err := connection.FormatUrl(opts) if err != nil { c.JSON(400, Error{err.Error()}) return } if c.Request.FormValue("ssh") != "" { sshInfo = parseSshInfo(c) } cl, err := client.NewFromUrl(url, sshInfo) if err != nil { c.JSON(400, Error{err.Error()}) return } err = cl.Test() if err != nil { c.JSON(400, Error{err.Error()}) return } info, err := cl.Info() if err == nil { err = setClient(c, cl) if err != nil { cl.Close() c.JSON(400, Error{err.Error()}) return } } c.JSON(200, info.Format()[0]) }
func Connect(c *gin.Context) { url := c.Request.FormValue("url") if url == "" { c.JSON(400, Error{"Url parameter is required"}) return } opts := command.Options{Url: url} url, err := connection.FormatUrl(opts) if err != nil { c.JSON(400, Error{err.Error()}) return } cl, err := client.NewFromUrl(url) if err != nil { c.JSON(400, Error{err.Error()}) return } err = cl.Test() if err != nil { c.JSON(400, Error{err.Error()}) return } info, err := cl.Info() if err == nil { err = setClient(c, cl) if err != nil { cl.Close() c.JSON(400, Error{err.Error()}) return } } c.JSON(200, info.Format()[0]) }