Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
add DownloadProgress and UploadProgress useage
  • Loading branch information
imroc committed Jun 12, 2017
1 parent 9224a9a commit 127e8b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,29 @@ req.Post(url, req.FileUpload{
FileName: "avatar.png", //Filename is the name of the file that you wish to upload. We use this to guess the mimetype as well as pass it onto the server
})
```
Use `req.UploadProgress` to listen upload progress
```go
progress := func(current, total int64) {
fmt.Println(float32(current)/float32(total)*100, "%")
}
req.Post(url, req.File("/Users/roc/Pictures/*.png"), req.UploadProgress(progress))
fmt.Println("upload complete")
```

## <a name="Download">Download</a>
``` go
r, _ := req.Get(url)
r.ToFile("imroc.png")
```
Use `req.DownloadProgress` to listen download progress
```go
progress := func(current, total int64) {
fmt.Println(float32(current)/float32(total)*100, "%")
}
r, _ := req.Get(url, req.DownloadProgress(progress))
r.ToFile("hello.mp4")
fmt.Println("download complete")
```

## <a name="Cookie">Cookie</a>
By default, the underlying `*http.Client` will manage your cookie(send cookie header to server automatically if server has set a cookie for you), you can disable it by calling this function :
Expand Down
17 changes: 17 additions & 0 deletions doc/README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,29 @@ req.Post(url, req.FileUpload{
FileName: "avatar.png", // Filename 是要上传的文件的名称,我们使用它来猜测mimetype,并将其上传到服务器上
})
```
使用`req.UploadProgress`监听上传进度
```go
progress := func(current, total int64) {
fmt.Println(float32(current)/float32(total)*100, "%")
}
req.Post(url, req.File("/Users/roc/Pictures/*.png"), req.UploadProgress(progress))
fmt.Println("upload complete")
```

## <a name="Download">下载</a>
``` go
r, _ := req.Get(url)
r.ToFile("imroc.png")
```
使用`req.DownloadProgress`监听下载进度
```go
progress := func(current, total int64) {
fmt.Println(float32(current)/float32(total)*100, "%")
}
r, _ := req.Get(url, req.DownloadProgress(progress))
r.ToFile("hello.mp4")
fmt.Println("download complete")
```

## <a name="Cookie">Cookie</a>
默认情况下,底层的 `*http.Client` 会自动管理你的cookie(如果服务器给你发了cookie,之后的请求它会自动带上cookie请求头给服务器), 你可以调用这个方法取消自动管理:
Expand Down

0 comments on commit 127e8b6

Please sign in to comment.