Replace DialWithOptions with Dial
No need for a dedicated function as Dial can take no options.
This commit is contained in:
parent
9b5a3addd7
commit
e6de3d35bf
@ -16,7 +16,7 @@ go get -u github.com/jlaffaye/ftp
|
||||
## Example ##
|
||||
|
||||
```go
|
||||
c, err := ftp.DialWithOptions("ftp.example.org:21", ftp.DialWithTimeout(5*time.Second))
|
||||
c, err := ftp.Dial("ftp.example.org:21", ftp.DialWithTimeout(5*time.Second))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ func openConn(t *testing.T, addr string, options ...DialOption) (*ftpMock, *Serv
|
||||
}
|
||||
defer mock.Close()
|
||||
|
||||
c, err := DialWithOptions(mock.Addr(), options...)
|
||||
c, err := Dial(mock.Addr(), options...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
13
ftp.go
13
ftp.go
@ -40,7 +40,7 @@ type ServerConn struct {
|
||||
mlstSupported bool
|
||||
}
|
||||
|
||||
// DialOption represents an option to start a new connection with DialWithOptions
|
||||
// DialOption represents an option to start a new connection with Dial
|
||||
type DialOption struct {
|
||||
setup func(do *dialOptions)
|
||||
}
|
||||
@ -71,8 +71,8 @@ type Response struct {
|
||||
closed bool
|
||||
}
|
||||
|
||||
// DialWithOptions connects to the specified address with optinal options
|
||||
func DialWithOptions(addr string, options ...DialOption) (*ServerConn, error) {
|
||||
// Dial connects to the specified address with optinal options
|
||||
func Dial(addr string, options ...DialOption) (*ServerConn, error) {
|
||||
do := &dialOptions{}
|
||||
for _, option := range options {
|
||||
option.setup(do)
|
||||
@ -197,17 +197,12 @@ func Connect(addr string) (*ServerConn, error) {
|
||||
return Dial(addr)
|
||||
}
|
||||
|
||||
// Dial is like DialTimeout with no timeout
|
||||
func Dial(addr string) (*ServerConn, error) {
|
||||
return DialTimeout(addr, 0)
|
||||
}
|
||||
|
||||
// DialTimeout initializes the connection to the specified ftp server address.
|
||||
//
|
||||
// It is generally followed by a call to Login() as most FTP commands require
|
||||
// an authenticated user.
|
||||
func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) {
|
||||
return DialWithOptions(addr, DialWithTimeout(timeout))
|
||||
return Dial(addr, DialWithTimeout(timeout))
|
||||
}
|
||||
|
||||
// Login authenticates the client with specified user and password.
|
||||
|
Loading…
Reference in New Issue
Block a user