Merge pull request #212 from mafredri/remove-naked-returns
Remove naked returns
This commit is contained in:
		
						commit
						9aec86d811
					
				
							
								
								
									
										39
									
								
								ftp.go
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								ftp.go
									
									
									
									
									
								
							@ -381,53 +381,48 @@ func (c *ServerConn) setUTF8() error {
 | 
				
			|||||||
func (c *ServerConn) epsv() (port int, err error) {
 | 
					func (c *ServerConn) epsv() (port int, err error) {
 | 
				
			||||||
	_, line, err := c.cmd(StatusExtendedPassiveMode, "EPSV")
 | 
						_, line, err := c.cmd(StatusExtendedPassiveMode, "EPSV")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return
 | 
							return 0, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	start := strings.Index(line, "|||")
 | 
						start := strings.Index(line, "|||")
 | 
				
			||||||
	end := strings.LastIndex(line, "|")
 | 
						end := strings.LastIndex(line, "|")
 | 
				
			||||||
	if start == -1 || end == -1 {
 | 
						if start == -1 || end == -1 {
 | 
				
			||||||
		err = errors.New("invalid EPSV response format")
 | 
							return 0, errors.New("invalid EPSV response format")
 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	port, err = strconv.Atoi(line[start+3 : end])
 | 
						port, err = strconv.Atoi(line[start+3 : end])
 | 
				
			||||||
	return
 | 
						return port, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// pasv issues a "PASV" command to get a port number for a data connection.
 | 
					// pasv issues a "PASV" command to get a port number for a data connection.
 | 
				
			||||||
func (c *ServerConn) pasv() (host string, port int, err error) {
 | 
					func (c *ServerConn) pasv() (host string, port int, err error) {
 | 
				
			||||||
	_, line, err := c.cmd(StatusPassiveMode, "PASV")
 | 
						_, line, err := c.cmd(StatusPassiveMode, "PASV")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return
 | 
							return "", 0, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// PASV response format : 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
 | 
						// PASV response format : 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
 | 
				
			||||||
	start := strings.Index(line, "(")
 | 
						start := strings.Index(line, "(")
 | 
				
			||||||
	end := strings.LastIndex(line, ")")
 | 
						end := strings.LastIndex(line, ")")
 | 
				
			||||||
	if start == -1 || end == -1 {
 | 
						if start == -1 || end == -1 {
 | 
				
			||||||
		err = errors.New("invalid PASV response format")
 | 
							return "", 0, errors.New("invalid PASV response format")
 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// We have to split the response string
 | 
						// We have to split the response string
 | 
				
			||||||
	pasvData := strings.Split(line[start+1:end], ",")
 | 
						pasvData := strings.Split(line[start+1:end], ",")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(pasvData) < 6 {
 | 
						if len(pasvData) < 6 {
 | 
				
			||||||
		err = errors.New("invalid PASV response format")
 | 
							return "", 0, errors.New("invalid PASV response format")
 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Let's compute the port number
 | 
						// Let's compute the port number
 | 
				
			||||||
	portPart1, err1 := strconv.Atoi(pasvData[4])
 | 
						portPart1, err := strconv.Atoi(pasvData[4])
 | 
				
			||||||
	if err1 != nil {
 | 
						if err != nil {
 | 
				
			||||||
		err = err1
 | 
							return "", 0, err
 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	portPart2, err2 := strconv.Atoi(pasvData[5])
 | 
						portPart2, err := strconv.Atoi(pasvData[5])
 | 
				
			||||||
	if err2 != nil {
 | 
						if err != nil {
 | 
				
			||||||
		err = err2
 | 
							return "", 0, err
 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Recompose port
 | 
						// Recompose port
 | 
				
			||||||
@ -435,7 +430,7 @@ func (c *ServerConn) pasv() (host string, port int, err error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Make the IP address to connect to
 | 
						// Make the IP address to connect to
 | 
				
			||||||
	host = strings.Join(pasvData[0:4], ".")
 | 
						host = strings.Join(pasvData[0:4], ".")
 | 
				
			||||||
	return
 | 
						return host, port, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// getDataConnPort returns a host, port for a new data connection
 | 
					// getDataConnPort returns a host, port for a new data connection
 | 
				
			||||||
@ -535,7 +530,7 @@ func (c *ServerConn) cmdDataConnFrom(offset uint64, format string, args ...inter
 | 
				
			|||||||
func (c *ServerConn) NameList(path string) (entries []string, err error) {
 | 
					func (c *ServerConn) NameList(path string) (entries []string, err error) {
 | 
				
			||||||
	conn, err := c.cmdDataConnFrom(0, "NLST %s", path)
 | 
						conn, err := c.cmdDataConnFrom(0, "NLST %s", path)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	r := &Response{conn: conn, c: c}
 | 
						r := &Response{conn: conn, c: c}
 | 
				
			||||||
@ -548,7 +543,7 @@ func (c *ServerConn) NameList(path string) (entries []string, err error) {
 | 
				
			|||||||
	if err = scanner.Err(); err != nil {
 | 
						if err = scanner.Err(); err != nil {
 | 
				
			||||||
		return entries, err
 | 
							return entries, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return
 | 
						return entries, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// List issues a LIST FTP command.
 | 
					// List issues a LIST FTP command.
 | 
				
			||||||
@ -566,7 +561,7 @@ func (c *ServerConn) List(path string) (entries []*Entry, err error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	conn, err := c.cmdDataConnFrom(0, "%s %s", cmd, path)
 | 
						conn, err := c.cmdDataConnFrom(0, "%s %s", cmd, path)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	r := &Response{conn: conn, c: c}
 | 
						r := &Response{conn: conn, c: c}
 | 
				
			||||||
@ -583,7 +578,7 @@ func (c *ServerConn) List(path string) (entries []*Entry, err error) {
 | 
				
			|||||||
	if err := scanner.Err(); err != nil {
 | 
						if err := scanner.Err(); err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return
 | 
						return entries, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ChangeDir issues a CWD FTP command, which changes the current directory to
 | 
					// ChangeDir issues a CWD FTP command, which changes the current directory to
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user