mirror of
				https://github.com/appleboy/drone-ssh.git
				synced 2025-10-29 00:51:15 +08:00 
			
		
		
		
	[easyssh] Change timeout type to time.Duration in Run and Stream Method (appleboy/easyssh-proxy#37)
* Change timeout type to time.Duration in Run and Stream Method * Correct Connect method comment https://github.com/appleboy/drone-ssh/commit/c193b89aa23
This commit is contained in:
		
							parent
							
								
									cfa11e851a
								
							
						
					
					
						commit
						575df3ab1c
					
				
							
								
								
									
										10
									
								
								vendor/github.com/appleboy/easyssh-proxy/easyssh.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								vendor/github.com/appleboy/easyssh-proxy/easyssh.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @ -161,20 +161,20 @@ func (ssh_conf *MakeConfig) Connect() (*ssh.Session, error) { | |||||||
| // Stream returns one channel that combines the stdout and stderr of the command
 | // Stream returns one channel that combines the stdout and stderr of the command
 | ||||||
| // as it is run on the remote machine, and another that sends true when the
 | // as it is run on the remote machine, and another that sends true when the
 | ||||||
| // command is done. The sessions and channels will then be closed.
 | // command is done. The sessions and channels will then be closed.
 | ||||||
| func (ssh_conf *MakeConfig) Stream(command string, timeout int) (<-chan string, <-chan string, <-chan bool, <-chan error, error) { | func (ssh_conf *MakeConfig) Stream(command string, timeout time.Duration) (<-chan string, <-chan string, <-chan bool, <-chan error, error) { | ||||||
| 	// continuously send the command's output over the channel
 | 	// continuously send the command's output over the channel
 | ||||||
| 	stdoutChan := make(chan string) | 	stdoutChan := make(chan string) | ||||||
| 	stderrChan := make(chan string) | 	stderrChan := make(chan string) | ||||||
| 	doneChan := make(chan bool) | 	doneChan := make(chan bool) | ||||||
| 	errChan := make(chan error) | 	errChan := make(chan error) | ||||||
| 
 | 
 | ||||||
| 	// Connect to remote host
 | 	// connect to remote host
 | ||||||
| 	session, err := ssh_conf.Connect() | 	session, err := ssh_conf.Connect() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return stdoutChan, stderrChan, doneChan, errChan, err | 		return stdoutChan, stderrChan, doneChan, errChan, err | ||||||
| 	} | 	} | ||||||
| 	// defer session.Close()
 | 	// defer session.Close()
 | ||||||
| 	// Connect to both outputs (they are of type io.Reader)
 | 	// connect to both outputs (they are of type io.Reader)
 | ||||||
| 	outReader, err := session.StdoutPipe() | 	outReader, err := session.StdoutPipe() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return stdoutChan, stderrChan, doneChan, errChan, err | 		return stdoutChan, stderrChan, doneChan, errChan, err | ||||||
| @ -201,7 +201,7 @@ func (ssh_conf *MakeConfig) Stream(command string, timeout int) (<-chan string, | |||||||
| 		defer close(errChan) | 		defer close(errChan) | ||||||
| 		defer session.Close() | 		defer session.Close() | ||||||
| 
 | 
 | ||||||
| 		timeoutChan := time.After(time.Duration(timeout) * time.Second) | 		timeoutChan := time.After(timeout * time.Second) | ||||||
| 		res := make(chan bool, 1) | 		res := make(chan bool, 1) | ||||||
| 
 | 
 | ||||||
| 		go func() { | 		go func() { | ||||||
| @ -230,7 +230,7 @@ func (ssh_conf *MakeConfig) Stream(command string, timeout int) (<-chan string, | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Run command on remote machine and returns its stdout as a string
 | // Run command on remote machine and returns its stdout as a string
 | ||||||
| func (ssh_conf *MakeConfig) Run(command string, timeout int) (outStr string, errStr string, isTimeout bool, err error) { | func (ssh_conf *MakeConfig) Run(command string, timeout time.Duration) (outStr string, errStr string, isTimeout bool, err error) { | ||||||
| 	stdoutChan, stderrChan, doneChan, errChan, err := ssh_conf.Stream(command, timeout) | 	stdoutChan, stderrChan, doneChan, errChan, err := ssh_conf.Stream(command, timeout) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return outStr, errStr, isTimeout, err | 		return outStr, errStr, isTimeout, err | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 SebastienDorgan
						SebastienDorgan