-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from bot-api/fix-mock
Fix go 1.7 tests, Add session middleware and DownloadFile method for api
- Loading branch information
Showing
10 changed files
with
299 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// +build go1.7 | ||
|
||
package telegram | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
// these errors are from net/http for go 1.7 | ||
const ( | ||
errRequestCanceled = "net/http: request canceled" | ||
errRequestCanceledConn = "net/http: request canceled while waiting for connection" | ||
) | ||
|
||
func makeRequest(ctx context.Context, client HTTPDoer, req *http.Request) (*http.Response, error) { | ||
var ( | ||
resp *http.Response | ||
err error | ||
) | ||
if httpClient, ok := client.(*http.Client); ok { | ||
resp, err = httpClient.Do(req.WithContext(ctx)) | ||
} else { | ||
// TODO: implement cancel logic for non http.Client | ||
resp, err = client.Do(req) | ||
} | ||
if err != nil { | ||
if urlErr, casted := err.(*url.Error); casted { | ||
if urlErr.Err == context.Canceled { | ||
return resp, context.Canceled | ||
} | ||
errMsg := urlErr.Err.Error() | ||
if errMsg == errRequestCanceled || | ||
errMsg == errRequestCanceledConn { | ||
return resp, context.Canceled | ||
} | ||
} | ||
} | ||
return resp, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// +build !go1.7 | ||
|
||
package telegram | ||
|
||
import ( | ||
"net/http" | ||
|
||
"golang.org/x/net/context" | ||
"golang.org/x/net/context/ctxhttp" | ||
) | ||
|
||
func makeRequest(ctx context.Context, client HTTPDoer, req *http.Request) (*http.Response, error) { | ||
var ( | ||
resp *http.Response | ||
err error | ||
) | ||
if httpClient, ok := client.(*http.Client); ok { | ||
resp, err = ctxhttp.Do(ctx, httpClient, req) | ||
} else { | ||
// TODO: implement cancel logic for non http.Client | ||
resp, err = client.Do(req) | ||
} | ||
return resp, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.