Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
61e694f3
Commit
61e694f3
authored
Jan 03, 2017
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add retry
parent
195c9b24
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
httplib.go
httplib/httplib.go
+21
-2
No files found.
httplib/httplib.go
View file @
61e694f3
...
...
@@ -140,6 +140,7 @@ type BeegoHTTPSettings struct {
EnableCookie
bool
Gzip
bool
DumpBody
bool
Retries
int
// if set to -1 means will retry forever
}
// BeegoHTTPRequest provides more useful methods for requesting one url than http.Request.
...
...
@@ -189,6 +190,15 @@ func (b *BeegoHTTPRequest) Debug(isdebug bool) *BeegoHTTPRequest {
return
b
}
// Retries sets Retries times.
// default is 0 means no retried.
// -1 means retried forever.
// others means retried times.
func
(
b
*
BeegoHTTPRequest
)
Retries
(
times
int
)
*
BeegoHTTPRequest
{
b
.
setting
.
Retries
=
times
return
b
}
// DumpBody setting whether need to Dump the Body.
func
(
b
*
BeegoHTTPRequest
)
DumpBody
(
isdump
bool
)
*
BeegoHTTPRequest
{
b
.
setting
.
DumpBody
=
isdump
...
...
@@ -390,7 +400,7 @@ func (b *BeegoHTTPRequest) getResponse() (*http.Response, error) {
}
// DoRequest will do the client.Do
func
(
b
*
BeegoHTTPRequest
)
DoRequest
()
(
*
http
.
Response
,
error
)
{
func
(
b
*
BeegoHTTPRequest
)
DoRequest
()
(
resp
*
http
.
Response
,
err
error
)
{
var
paramBody
string
if
len
(
b
.
params
)
>
0
{
var
buf
bytes
.
Buffer
...
...
@@ -467,7 +477,16 @@ func (b *BeegoHTTPRequest) DoRequest() (*http.Response, error) {
}
b
.
dump
=
dump
}
return
client
.
Do
(
b
.
req
)
// retries default value is 0, it will run once.
// retries equal to -1, it will run forever until success
// retries is setted, it will retries fixed times.
for
i
:=
0
;
i
==
0
||
b
.
setting
.
Retries
==
-
1
||
i
<
b
.
setting
.
Retries
;
i
++
{
resp
,
err
=
client
.
Do
(
b
.
req
)
if
err
==
nil
{
break
}
}
return
resp
,
err
}
// String returns the body string in response.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment