mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 00:10:25 +08:00 
			
		
		
		
	reafctor: pool
This commit is contained in:
		@@ -18,11 +18,41 @@ type Cli struct {
 | 
			
		||||
	sftpClient *sftp.Client // sftp客户端
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/******************* pool.Conn impl *******************/
 | 
			
		||||
 | 
			
		||||
func (c *Cli) Ping() error {
 | 
			
		||||
	_, _, err := c.sshClient.Conn.SendRequest("ping", true, nil)
 | 
			
		||||
	_, _, err := c.sshClient.SendRequest("ping", true, nil)
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Close 关闭client并从缓存中移除,如果使用隧道则也关闭
 | 
			
		||||
func (c *Cli) Close() error {
 | 
			
		||||
	m := c.Info
 | 
			
		||||
	logx.Debugf("close machine cli -> id=%d, name=%s, ip=%s", m.Id, m.Name, m.Ip)
 | 
			
		||||
	if c.sshClient != nil {
 | 
			
		||||
		c.sshClient.Close()
 | 
			
		||||
		c.sshClient = nil
 | 
			
		||||
	}
 | 
			
		||||
	if c.sftpClient != nil {
 | 
			
		||||
		c.sftpClient.Close()
 | 
			
		||||
		c.sftpClient = nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var sshTunnelMachineId uint64
 | 
			
		||||
	if m.SshTunnelMachine != nil {
 | 
			
		||||
		sshTunnelMachineId = m.SshTunnelMachine.Id
 | 
			
		||||
	}
 | 
			
		||||
	if m.TempSshMachineId != 0 {
 | 
			
		||||
		sshTunnelMachineId = m.TempSshMachineId
 | 
			
		||||
	}
 | 
			
		||||
	if sshTunnelMachineId != 0 {
 | 
			
		||||
		logx.Debugf("close machine ssh tunnel -> machineId=%d, sshTunnelMachineId=%d", m.Id, sshTunnelMachineId)
 | 
			
		||||
		CloseSshTunnelMachine(sshTunnelMachineId, m.GetTunnelId())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetSftpCli 获取sftp client
 | 
			
		||||
func (c *Cli) GetSftpCli() (*sftp.Client, error) {
 | 
			
		||||
	if c.sshClient == nil {
 | 
			
		||||
@@ -72,32 +102,6 @@ func (c *Cli) Run(shell string) (string, error) {
 | 
			
		||||
	return string(buf), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Close 关闭client并从缓存中移除,如果使用隧道则也关闭
 | 
			
		||||
func (c *Cli) Close() {
 | 
			
		||||
	m := c.Info
 | 
			
		||||
	logx.Debugf("close machine cli -> id=%d, name=%s, ip=%s", m.Id, m.Name, m.Ip)
 | 
			
		||||
	if c.sshClient != nil {
 | 
			
		||||
		c.sshClient.Close()
 | 
			
		||||
		c.sshClient = nil
 | 
			
		||||
	}
 | 
			
		||||
	if c.sftpClient != nil {
 | 
			
		||||
		c.sftpClient.Close()
 | 
			
		||||
		c.sftpClient = nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var sshTunnelMachineId uint64
 | 
			
		||||
	if m.SshTunnelMachine != nil {
 | 
			
		||||
		sshTunnelMachineId = m.SshTunnelMachine.Id
 | 
			
		||||
	}
 | 
			
		||||
	if m.TempSshMachineId != 0 {
 | 
			
		||||
		sshTunnelMachineId = m.TempSshMachineId
 | 
			
		||||
	}
 | 
			
		||||
	if sshTunnelMachineId != 0 {
 | 
			
		||||
		logx.Debugf("close machine ssh tunnel -> machineId=%d, sshTunnelMachineId=%d", m.Id, sshTunnelMachineId)
 | 
			
		||||
		CloseSshTunnelMachine(sshTunnelMachineId, m.GetTunnelId())
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetAllStats 获取机器的所有状态信息
 | 
			
		||||
func (c *Cli) GetAllStats() *Stats {
 | 
			
		||||
	stats := new(Stats)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user