Skip to content

Commit

Permalink
Replace DialWithOptions with Dial
Browse files Browse the repository at this point in the history
No need for a dedicated function as Dial can take no options.
  • Loading branch information
jlaffaye committed Apr 23, 2019
1 parent 9b5a3ad commit e6de3d3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 4 additions & 9 deletions ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e6de3d3

Please sign in to comment.