Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a2da87a06 | ||
|
|
c07e49771c | ||
|
|
6da3d4094c | ||
|
|
72e7751604 | ||
|
|
5057561906 | ||
|
|
3b45c0ae0e | ||
|
|
ba2e64b62e | ||
|
|
b8afb3f850 | ||
|
|
b44176ed7c | ||
|
|
757ad28a32 | ||
|
|
f7881abec6 | ||
|
|
0c4356fe8e | ||
|
|
e3a89ee58b | ||
|
|
08b8ff8ae7 | ||
|
|
4899c226f7 | ||
|
|
dad5b1f3fb | ||
|
|
2afc5e192c | ||
|
|
e39f3e3585 | ||
|
|
ca3ea38770 |
55
.github/workflows/auto-changelog.yml
vendored
Normal file
55
.github/workflows/auto-changelog.yml
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
name: ChangeLog
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: '12'
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout Tool
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: konakonall/auto-changelog
|
||||
path: 'auto-changelog'
|
||||
- name: Build Tool
|
||||
run: |
|
||||
cd auto-changelog
|
||||
npm install
|
||||
npm link
|
||||
|
||||
- name: Generate ChangeLog
|
||||
env: # Or as an environment variable
|
||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
auto-changelog --token $TOKEN
|
||||
- name: Cat ChangeLog
|
||||
run: cat CHANGELOG.md
|
||||
|
||||
- name: Commit files
|
||||
env:
|
||||
CI_USER: "gouki0123"
|
||||
CI_EMAIL: "gouki0123@gmail.com"
|
||||
run: |
|
||||
git config --local user.email "$CI_EMAIL"
|
||||
git config --local user.name "$CI_USER"
|
||||
git add CHANGELOG.md && git commit -m 'Updated CHANGELOG.md' && echo "push=1" >> $GITHUB_ENV || echo "No changes to CHANGELOG.md"
|
||||
|
||||
- name: Push changes
|
||||
if: env.push == 1
|
||||
env:
|
||||
CI_USER: "gouki0123"
|
||||
CI_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
git push "https://$CI_USER:$CI_TOKEN@github.com/$GITHUB_REPOSITORY.git" HEAD:master
|
||||
239
CHANGELOG.md
Normal file
239
CHANGELOG.md
Normal file
@@ -0,0 +1,239 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||
|
||||
## [v0.7.15](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.14...v0.7.15) - 2020-12-11
|
||||
|
||||
update ci & ci document
|
||||
|
||||
### Merged
|
||||
|
||||
- update ci [`#96`](https://github.com/tencentyun/cos-go-sdk-v5/pull/96)
|
||||
|
||||
### Commits
|
||||
|
||||
- Updated CHANGELOG.md [`b8afb3f`](https://github.com/tencentyun/cos-go-sdk-v5/commit/b8afb3f85050cee4884a46c8ed49d26bf76d10a4)
|
||||
|
||||
## [v0.7.14](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.13...v0.7.14) - 2020-12-09
|
||||
|
||||
fix bucket lifecycle
|
||||
|
||||
### Merged
|
||||
|
||||
- update version [`#95`](https://github.com/tencentyun/cos-go-sdk-v5/pull/95)
|
||||
- fix bucket lifecycle [`#94`](https://github.com/tencentyun/cos-go-sdk-v5/pull/94)
|
||||
|
||||
### Commits
|
||||
|
||||
- Updated CHANGELOG.md [`e3a89ee`](https://github.com/tencentyun/cos-go-sdk-v5/commit/e3a89ee58b4f524c7ad5f2b1f0bdc688a2e39c32)
|
||||
|
||||
## [v0.7.13](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.12...v0.7.13) - 2020-12-08
|
||||
|
||||
add ci document && add progress
|
||||
|
||||
### Merged
|
||||
|
||||
- Cos v4 dev [`#93`](https://github.com/tencentyun/cos-go-sdk-v5/pull/93)
|
||||
|
||||
### Commits
|
||||
|
||||
- add ci doc [`dad5b1f`](https://github.com/tencentyun/cos-go-sdk-v5/commit/dad5b1f3fbbf30958d3d8ae930b06abcaf8db5ac)
|
||||
- add progress [`2afc5e1`](https://github.com/tencentyun/cos-go-sdk-v5/commit/2afc5e192cd9bc8d6630fa929e10028ec79bde8e)
|
||||
- Updated CHANGELOG.md [`e39f3e3`](https://github.com/tencentyun/cos-go-sdk-v5/commit/e39f3e3585e0478abe50b33962e1e3981a2d432c)
|
||||
- update test [`4899c22`](https://github.com/tencentyun/cos-go-sdk-v5/commit/4899c226f70ccc1bb4ac8489a2b8ff000003bc97)
|
||||
- add auto changelog workflow [`ca3ea38`](https://github.com/tencentyun/cos-go-sdk-v5/commit/ca3ea38770afcd11e50570a835090c68a377157f)
|
||||
|
||||
## [v0.7.12](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.11...v0.7.12) - 2020-11-25
|
||||
|
||||
update presignedurl && copy
|
||||
|
||||
### Merged
|
||||
|
||||
- fix ci_test [`#89`](https://github.com/tencentyun/cos-go-sdk-v5/pull/89)
|
||||
- update version [`#92`](https://github.com/tencentyun/cos-go-sdk-v5/pull/92)
|
||||
- update presignedurl && copy [`#91`](https://github.com/tencentyun/cos-go-sdk-v5/pull/91)
|
||||
|
||||
## [v0.7.11](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.10...v0.7.11) - 2020-11-15
|
||||
|
||||
断点续传、select、CI内容审核、CI云上处理、单链接限制
|
||||
|
||||
### Merged
|
||||
|
||||
- Cos v4 dev [`#90`](https://github.com/tencentyun/cos-go-sdk-v5/pull/90)
|
||||
|
||||
### Commits
|
||||
|
||||
- add select, and x-cos-traffic-limit [`e6f823c`](https://github.com/tencentyun/cos-go-sdk-v5/commit/e6f823c7c1ee66fe68de4aafd45b009dee4b1ac2)
|
||||
- add ListMultiUploads && 断点续传 [`64d31f3`](https://github.com/tencentyun/cos-go-sdk-v5/commit/64d31f318a223866ac16c64bbe9effcd168b696d)
|
||||
- ci 内容审核 [`695c446`](https://github.com/tencentyun/cos-go-sdk-v5/commit/695c4466f5cec17acd5143777d4eae90f389f119)
|
||||
- add checkpoint multi upload [`287669a`](https://github.com/tencentyun/cos-go-sdk-v5/commit/287669a677af36153d645aabd4b296114aea75fe)
|
||||
- add ci post [`dd7c41c`](https://github.com/tencentyun/cos-go-sdk-v5/commit/dd7c41ca0824b607633e6a7bd0d3a838d52a91fd)
|
||||
- add CI图片审核 [`98eab28`](https://github.com/tencentyun/cos-go-sdk-v5/commit/98eab2886c628a3fbbbf581aeea56759ff38700c)
|
||||
- fix list uploads [`5e69c19`](https://github.com/tencentyun/cos-go-sdk-v5/commit/5e69c19d3450d06c3da270ca12e43647432d0ca4)
|
||||
- add decodeURIComponent [`f6c91c9`](https://github.com/tencentyun/cos-go-sdk-v5/commit/f6c91c92d6e46869c8f7acf000eccce2d351051b)
|
||||
- add checkpoint multi upload: update [`52c110b`](https://github.com/tencentyun/cos-go-sdk-v5/commit/52c110b7ede92af97e3685d4afd73a128ddd443b)
|
||||
|
||||
## [v0.7.10](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.9...v0.7.10) - 2020-09-29
|
||||
|
||||
add delete with versionid & fix MultiUpload when filesize equal 0 & Bucket/Object ACL transform
|
||||
|
||||
### Merged
|
||||
|
||||
- ACL转换 [`#87`](https://github.com/tencentyun/cos-go-sdk-v5/pull/87)
|
||||
- fix bucket encryption & test [`#86`](https://github.com/tencentyun/cos-go-sdk-v5/pull/86)
|
||||
|
||||
### Commits
|
||||
|
||||
- fix MultiUpload when filesize=0 [`cb662cd`](https://github.com/tencentyun/cos-go-sdk-v5/commit/cb662cdad5225cf92be335911d1805a29e445d14)
|
||||
- 多版本删除 [`0e9536d`](https://github.com/tencentyun/cos-go-sdk-v5/commit/0e9536d989b8e47b71fa02d12cb75d8ffda8b5fc)
|
||||
- update travis.yml [`b0a399e`](https://github.com/tencentyun/cos-go-sdk-v5/commit/b0a399e92dd143fb55b1ed173497644e51450835)
|
||||
- update version [`5804e86`](https://github.com/tencentyun/cos-go-sdk-v5/commit/5804e86747f587402b962dcb680ebc0d7c04035d)
|
||||
|
||||
## [v0.7.9](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.8...v0.7.9) - 2020-09-14
|
||||
|
||||
add bucket intelligenttiering
|
||||
|
||||
### Merged
|
||||
|
||||
- add bucket intelligenttiering [`#85`](https://github.com/tencentyun/cos-go-sdk-v5/pull/85)
|
||||
|
||||
## [v0.7.8](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.7...v0.7.8) - 2020-08-31
|
||||
|
||||
x-cos-copy-source urlencode修正
|
||||
|
||||
### Merged
|
||||
|
||||
- x-cos-copy-source urlencode修正 [`#83`](https://github.com/tencentyun/cos-go-sdk-v5/pull/83)
|
||||
- Common dev [`#82`](https://github.com/tencentyun/cos-go-sdk-v5/pull/82)
|
||||
|
||||
### Commits
|
||||
|
||||
- add host to signature [`f9f6178`](https://github.com/tencentyun/cos-go-sdk-v5/commit/f9f617878dad23f915ecea978f065aa70486843c)
|
||||
|
||||
## [v0.7.7](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.6...v0.7.7) - 2020-06-04
|
||||
|
||||
add object tagging && bucket origin && add stsv3 demo
|
||||
|
||||
### Merged
|
||||
|
||||
- add object tagging && bucket origin && add stsv3 demo [`#80`](https://github.com/tencentyun/cos-go-sdk-v5/pull/80)
|
||||
|
||||
## [v0.7.6](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.5...v0.7.6) - 2020-05-20
|
||||
|
||||
Add PutBucketObjectVersions
|
||||
|
||||
### Merged
|
||||
|
||||
- add GetBucketObjectVersions & update tips when failed [`#78`](https://github.com/tencentyun/cos-go-sdk-v5/pull/78)
|
||||
|
||||
### Commits
|
||||
|
||||
- update version [`bcc1ed2`](https://github.com/tencentyun/cos-go-sdk-v5/commit/bcc1ed2b8317cea8a32ab193ffad0a6482d63560)
|
||||
|
||||
## [v0.7.5](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.4...v0.7.5) - 2020-05-14
|
||||
|
||||
add HeaderOptions to Object.Delete
|
||||
|
||||
### Merged
|
||||
|
||||
- update tag 0.7.5 [`#77`](https://github.com/tencentyun/cos-go-sdk-v5/pull/77)
|
||||
- feat: Object.Delete 增加 optHeader 传递 [`#75`](https://github.com/tencentyun/cos-go-sdk-v5/pull/75)
|
||||
|
||||
### Commits
|
||||
|
||||
- feat: 改为可选参数,向下兼容 [`2eee514`](https://github.com/tencentyun/cos-go-sdk-v5/commit/2eee5149d727a045e80d28729bb60c90614e8275)
|
||||
|
||||
## [v0.7.4](https://github.com/tencentyun/cos-go-sdk-v5/compare/v0.7.3...v0.7.4) - 2020-04-12
|
||||
|
||||
add put/get bucket eferer and put/get/delete bucket encryption
|
||||
|
||||
### Merged
|
||||
|
||||
- add encryption and referer [`#74`](https://github.com/tencentyun/cos-go-sdk-v5/pull/74)
|
||||
|
||||
### Commits
|
||||
|
||||
- version 0.7.4 [`da7722b`](https://github.com/tencentyun/cos-go-sdk-v5/commit/da7722b10af59762b8e4f687891850650f0100a9)
|
||||
|
||||
## v0.7.3 - 2020-04-02
|
||||
|
||||
update ci
|
||||
|
||||
### Merged
|
||||
|
||||
- update ci and error [`#73`](https://github.com/tencentyun/cos-go-sdk-v5/pull/73)
|
||||
- add policy and IsNoSuchKeyError function [`#72`](https://github.com/tencentyun/cos-go-sdk-v5/pull/72)
|
||||
- add restore object for batch [`#69`](https://github.com/tencentyun/cos-go-sdk-v5/pull/69)
|
||||
- Addbatch [`#68`](https://github.com/tencentyun/cos-go-sdk-v5/pull/68)
|
||||
- inventory/logging/replication/versioning/tagging [`#66`](https://github.com/tencentyun/cos-go-sdk-v5/pull/66)
|
||||
- add content-language [`#65`](https://github.com/tencentyun/cos-go-sdk-v5/pull/65)
|
||||
- add host [`#64`](https://github.com/tencentyun/cos-go-sdk-v5/pull/64)
|
||||
- update MultiUpload [`#63`](https://github.com/tencentyun/cos-go-sdk-v5/pull/63)
|
||||
- add bucket website and domain interface [`#53`](https://github.com/tencentyun/cos-go-sdk-v5/pull/53)
|
||||
- 改进:增加对Upload part - copy API的支持 [`#54`](https://github.com/tencentyun/cos-go-sdk-v5/pull/54)
|
||||
- add sts policy describe [`#60`](https://github.com/tencentyun/cos-go-sdk-v5/pull/60)
|
||||
- update the sts example [`#59`](https://github.com/tencentyun/cos-go-sdk-v5/pull/59)
|
||||
- Automatic partitioning for MultiUpload [`#58`](https://github.com/tencentyun/cos-go-sdk-v5/pull/58)
|
||||
- add sse-c and optional header for put object [`#57`](https://github.com/tencentyun/cos-go-sdk-v5/pull/57)
|
||||
- fix object upload copy versionid [`#56`](https://github.com/tencentyun/cos-go-sdk-v5/pull/56)
|
||||
- Fix the multiupload property [`#50`](https://github.com/tencentyun/cos-go-sdk-v5/pull/50)
|
||||
- Fix the mulupload out of index panic [`#49`](https://github.com/tencentyun/cos-go-sdk-v5/pull/49)
|
||||
- fix the example of get, reorder the import package [`#48`](https://github.com/tencentyun/cos-go-sdk-v5/pull/48)
|
||||
- spec the test bucket only used for test [`#47`](https://github.com/tencentyun/cos-go-sdk-v5/pull/47)
|
||||
- reopen the coverage report [`#46`](https://github.com/tencentyun/cos-go-sdk-v5/pull/46)
|
||||
- Fix the ci test [`#45`](https://github.com/tencentyun/cos-go-sdk-v5/pull/45)
|
||||
- add Server Side Encryption Option to ObjectPutHeaderOptions and fixed testing [`#44`](https://github.com/tencentyun/cos-go-sdk-v5/pull/44)
|
||||
- Fix the outindex of the resp addr in head object [`#42`](https://github.com/tencentyun/cos-go-sdk-v5/pull/42)
|
||||
- Add the check for anonymous user [`#41`](https://github.com/tencentyun/cos-go-sdk-v5/pull/41)
|
||||
- Change the param type in listParts [`#38`](https://github.com/tencentyun/cos-go-sdk-v5/pull/38)
|
||||
- Fix the options param to listparts interface [`#37`](https://github.com/tencentyun/cos-go-sdk-v5/pull/37)
|
||||
- Add the error when return 200OK but body contains the error [`#34`](https://github.com/tencentyun/cos-go-sdk-v5/pull/34)
|
||||
- cgi already compact, so remove the sprit [`#32`](https://github.com/tencentyun/cos-go-sdk-v5/pull/32)
|
||||
- fix the blink in prefix which lead the wrong auth [`#31`](https://github.com/tencentyun/cos-go-sdk-v5/pull/31)
|
||||
- Support Versioning, Replication, Inventory and Logging API [`#30`](https://github.com/tencentyun/cos-go-sdk-v5/pull/30)
|
||||
- fix the panic of getting out of index with response header [`#28`](https://github.com/tencentyun/cos-go-sdk-v5/pull/28)
|
||||
- According the versionid to head and get object, add the opt header of copy object [`#26`](https://github.com/tencentyun/cos-go-sdk-v5/pull/26)
|
||||
- rm the panic in interface [`#24`](https://github.com/tencentyun/cos-go-sdk-v5/pull/24)
|
||||
- Add presigned url and demo use it to get object [`#23`](https://github.com/tencentyun/cos-go-sdk-v5/pull/23)
|
||||
- Check delete object param and fix restore name [`#22`](https://github.com/tencentyun/cos-go-sdk-v5/pull/22)
|
||||
- Add PostObjectRestore interface [`#21`](https://github.com/tencentyun/cos-go-sdk-v5/pull/21)
|
||||
- Add vendor files [`#19`](https://github.com/tencentyun/cos-go-sdk-v5/pull/19)
|
||||
- Add the comment to declare the out of memory issue when put large loc… [`#17`](https://github.com/tencentyun/cos-go-sdk-v5/pull/17)
|
||||
- Need to improve the interface in the future [`#16`](https://github.com/tencentyun/cos-go-sdk-v5/pull/16)
|
||||
- Add ci test with the testify and travis, Add get/put by localfile. [`#15`](https://github.com/tencentyun/cos-go-sdk-v5/pull/15)
|
||||
- url encode without / [`#14`](https://github.com/tencentyun/cos-go-sdk-v5/pull/14)
|
||||
- solve the oom when send the big file with the debug request header option [`#10`](https://github.com/tencentyun/cos-go-sdk-v5/pull/10)
|
||||
- remove the content-type when the request body is empty [`#9`](https://github.com/tencentyun/cos-go-sdk-v5/pull/9)
|
||||
- fix format [`#6`](https://github.com/tencentyun/cos-go-sdk-v5/pull/6)
|
||||
- fix format of doc [`#5`](https://github.com/tencentyun/cos-go-sdk-v5/pull/5)
|
||||
- update the comment for godoc [`#4`](https://github.com/tencentyun/cos-go-sdk-v5/pull/4)
|
||||
- fix test [`#3`](https://github.com/tencentyun/cos-go-sdk-v5/pull/3)
|
||||
- update rm the append interface [`#2`](https://github.com/tencentyun/cos-go-sdk-v5/pull/2)
|
||||
|
||||
### Commits
|
||||
|
||||
- fix the vendor files [`a5b3ad3`](https://github.com/tencentyun/cos-go-sdk-v5/commit/a5b3ad37d64c5aa82b12a57a6fdb0d2dba5ca1a8)
|
||||
- first to commit project [`6ad265f`](https://github.com/tencentyun/cos-go-sdk-v5/commit/6ad265fc0c275a4b1615c0f4702a7a992d8d299c)
|
||||
- add batch [`c57ac81`](https://github.com/tencentyun/cos-go-sdk-v5/commit/c57ac81a16da82605cc42bf9e0c8fd3af2cf62c5)
|
||||
- Support Versioning, Replication, Inventory and Logging api [`c131870`](https://github.com/tencentyun/cos-go-sdk-v5/commit/c131870916d7c29eb8c4a9512ea59ed7d7b09e18)
|
||||
- fix path [`121a7d8`](https://github.com/tencentyun/cos-go-sdk-v5/commit/121a7d861c8e0fb048aac5a8bc1a644414b16dc3)
|
||||
- fix the vendor file [`830b5c5`](https://github.com/tencentyun/cos-go-sdk-v5/commit/830b5c54a51d38b91e1432c7b216350a5c479ad0)
|
||||
- update bucket inventory/logging/replication/versioning/tagging and test [`d37fd23`](https://github.com/tencentyun/cos-go-sdk-v5/commit/d37fd23cdfe570886024c2c0586a2f14429a10ed)
|
||||
- Add ci test with the testify and travis, test the working [`4cc9e08`](https://github.com/tencentyun/cos-go-sdk-v5/commit/4cc9e08da1a0ce670cf6d20567059b7529b440d5)
|
||||
- Add ci test with the testify and travis, test the working [`c323f1b`](https://github.com/tencentyun/cos-go-sdk-v5/commit/c323f1b90cd97b98708216a72c666d89bdbcad8b)
|
||||
- rm inventory and logging example [`7739e84`](https://github.com/tencentyun/cos-go-sdk-v5/commit/7739e84d42b7a33121b16817f25129050db93db5)
|
||||
- add policy [`b427226`](https://github.com/tencentyun/cos-go-sdk-v5/commit/b427226ae44b1c0f25b8681147e828f4603a9014)
|
||||
- update batch [`156deae`](https://github.com/tencentyun/cos-go-sdk-v5/commit/156deaea3caacc5249050ae1e7378ae8af909c5d)
|
||||
- update bucket domain and website struct [`b97a490`](https://github.com/tencentyun/cos-go-sdk-v5/commit/b97a490e28370fecc475bf8b1a82df0d5a52a424)
|
||||
- presigned url, and demo [`0c2d28c`](https://github.com/tencentyun/cos-go-sdk-v5/commit/0c2d28caf108cff2a95507a9ff286be679d7925b)
|
||||
- fix ci_test [`c17efed`](https://github.com/tencentyun/cos-go-sdk-v5/commit/c17efed0aedee60e819d3e9504720ff47958da14)
|
||||
- fix [`9ebd645`](https://github.com/tencentyun/cos-go-sdk-v5/commit/9ebd6456b6aa788d0d2e97f4a8fb652c1b9a1976)
|
||||
- update batch [`699fef2`](https://github.com/tencentyun/cos-go-sdk-v5/commit/699fef215987bcf7f2459b9843ce8641900135f7)
|
||||
- Add the comment to declare the out of memory issue when put large local file [`6c894b8`](https://github.com/tencentyun/cos-go-sdk-v5/commit/6c894b8e4d5f0bb1ca24d444a9f8e18f95027cde)
|
||||
- go module support [`54101f9`](https://github.com/tencentyun/cos-go-sdk-v5/commit/54101f9739b3e59f201092f79d683a0cf377d7d0)
|
||||
- optional header for complete upload part [`44546a4`](https://github.com/tencentyun/cos-go-sdk-v5/commit/44546a40372260158652ddc6d805ddfc19f13fa3)
|
||||
4
batch.go
4
batch.go
@@ -13,7 +13,7 @@ type BatchRequestHeaders struct {
|
||||
XCosAppid int `header:"x-cos-appid" xml:"-" url:"-"`
|
||||
ContentLength string `header:"Content-Length,omitempty" xml:"-" url:"-"`
|
||||
ContentType string `header:"Content-Type,omitempty" xml:"-" url:"-"`
|
||||
Headers *http.Header `header:"-" xml:"-", url:"-"`
|
||||
Headers *http.Header `header:"-" xml:"-" url:"-"`
|
||||
}
|
||||
|
||||
// BatchProgressSummary
|
||||
@@ -244,7 +244,7 @@ func (s *BatchService) UpdateJobPriority(ctx context.Context, opt *BatchUpdatePr
|
||||
type BatchUpdateStatusOptions struct {
|
||||
JobId string `header:"-" url:"-" xml:"-"`
|
||||
RequestedJobStatus string `url:"requestedJobStatus" header:"-" xml:"-"`
|
||||
StatusUpdateReason string `url:"statusUpdateReason,omitempty" header:"-", xml:"-"`
|
||||
StatusUpdateReason string `url:"statusUpdateReason,omitempty" header:"-" xml:"-"`
|
||||
}
|
||||
type BatchUpdateStatusResult struct {
|
||||
XMLName xml.Name `xml:"UpdateJobStatusResult"`
|
||||
|
||||
37
bucket_accelerate.go
Normal file
37
bucket_accelerate.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package cos
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type BucketPutAccelerateOptions struct {
|
||||
XMLName xml.Name `xml:"AccelerateConfiguration"`
|
||||
Status string `xml:"Status,omitempty"`
|
||||
Type string `xml:"Type,omitempty"`
|
||||
}
|
||||
type BucketGetAccelerateResult BucketPutAccelerateOptions
|
||||
|
||||
func (s *BucketService) PutAccelerate(ctx context.Context, opt *BucketPutAccelerateOptions) (*Response, error) {
|
||||
sendOpt := &sendOptions{
|
||||
baseURL: s.client.BaseURL.BucketURL,
|
||||
uri: "/?accelerate",
|
||||
method: http.MethodPut,
|
||||
body: opt,
|
||||
}
|
||||
resp, err := s.client.send(ctx, sendOpt)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (s *BucketService) GetAccelerate(ctx context.Context) (*BucketGetAccelerateResult, *Response, error) {
|
||||
var res BucketGetAccelerateResult
|
||||
sendOpt := &sendOptions{
|
||||
baseURL: s.client.BaseURL.BucketURL,
|
||||
uri: "/?accelerate",
|
||||
method: http.MethodGet,
|
||||
result: &res,
|
||||
}
|
||||
resp, err := s.client.send(ctx, sendOpt)
|
||||
return &res, resp, err
|
||||
}
|
||||
74
bucket_accelerate_test.go
Normal file
74
bucket_accelerate_test.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package cos
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBucketService_GetAccelerate(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
vs := values{
|
||||
"accelerate": "",
|
||||
}
|
||||
testFormValues(t, r, vs)
|
||||
fmt.Fprint(w, `<AccelerateConfiguration>
|
||||
<Status>Enabled</Status>
|
||||
<Type>COS</Type>
|
||||
</AccelerateConfiguration>`)
|
||||
})
|
||||
|
||||
res, _, err := client.Bucket.GetAccelerate(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("Bucket.GetAccelerate returned error %v", err)
|
||||
}
|
||||
|
||||
want := &BucketGetAccelerateResult{
|
||||
XMLName: xml.Name{Local: "AccelerateConfiguration"},
|
||||
Status: "Enabled",
|
||||
Type: "COS",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(res, want) {
|
||||
t.Errorf("Bucket.GetAccelerate returned %+v, want %+v", res, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBucketService_PutAccelerate(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
opt := &BucketPutAccelerateOptions{
|
||||
XMLName: xml.Name{Local: "AccelerateConfiguration"},
|
||||
Status: "Enabled",
|
||||
Type: "COS",
|
||||
}
|
||||
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "PUT")
|
||||
vs := values{
|
||||
"accelerate": "",
|
||||
}
|
||||
testFormValues(t, r, vs)
|
||||
|
||||
body := new(BucketPutAccelerateOptions)
|
||||
xml.NewDecoder(r.Body).Decode(body)
|
||||
want := opt
|
||||
want.XMLName = xml.Name{Local: "AccelerateConfiguration"}
|
||||
if !reflect.DeepEqual(body, want) {
|
||||
t.Errorf("Bucket.PutAccelerate request\n body: %+v\n, want %+v\n", body, want)
|
||||
}
|
||||
})
|
||||
|
||||
_, err := client.Bucket.PutAccelerate(context.Background(), opt)
|
||||
if err != nil {
|
||||
t.Fatalf("Bucket.PutAccelerate returned error: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ type BucketLifecycleTransition struct {
|
||||
|
||||
// BucketLifecycleAbortIncompleteMultipartUpload is the param of BucketLifecycleRule
|
||||
type BucketLifecycleAbortIncompleteMultipartUpload struct {
|
||||
DaysAfterInitiation string `xml:"DaysAfterInititation,omitempty"`
|
||||
DaysAfterInitiation int `xml:"DaysAfterInitiation,omitempty"`
|
||||
}
|
||||
|
||||
// BucketLifecycleRule is the rule of BucketLifecycle
|
||||
|
||||
102
bucket_test.go
102
bucket_test.go
@@ -152,14 +152,14 @@ func TestBucketService_Head(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBucketService_GetObjectVersions(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
vs := values{
|
||||
"versions": "",
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
vs := values{
|
||||
"versions": "",
|
||||
"delimiter": "/",
|
||||
}
|
||||
testFormValues(t, r, vs)
|
||||
@@ -203,51 +203,51 @@ func TestBucketService_GetObjectVersions(t *testing.T) {
|
||||
</Owner>
|
||||
</DeleteMarker>
|
||||
</ListVersionsResult>`)
|
||||
})
|
||||
})
|
||||
|
||||
want := &BucketGetObjectVersionsResult {
|
||||
XMLName: xml.Name { Local: "ListVersionsResult" },
|
||||
Name: "examplebucket-1250000000",
|
||||
MaxKeys: 1000,
|
||||
IsTruncated: false,
|
||||
Delimiter: "/",
|
||||
CommonPrefixes: []string {
|
||||
"example-folder-1/",
|
||||
"example-folder-2/",
|
||||
},
|
||||
Version: []ListVersionsResultVersion {
|
||||
{
|
||||
Key: "example-object-1.jpg",
|
||||
VersionId: "MTg0NDUxNzgxMjEzNTU3NTk1Mjg",
|
||||
IsLatest: true,
|
||||
LastModified: "2019-08-16T10:45:53.000Z",
|
||||
ETag: "\"5d1143df07a17b23320d0da161e2819e\"",
|
||||
Size: 30,
|
||||
StorageClass: "STANDARD",
|
||||
Owner: &Owner {
|
||||
ID: "1250000000",
|
||||
DisplayName: "1250000000",
|
||||
},
|
||||
},
|
||||
},
|
||||
DeleteMarker: []ListVersionsResultDeleteMarker {
|
||||
{
|
||||
Key: "example-object-1.jpg",
|
||||
VersionId: "MTg0NDUxNzgxMjEzNjE1OTcxMzM",
|
||||
IsLatest: false,
|
||||
LastModified: "2019-08-16T10:45:47.000Z",
|
||||
Owner: &Owner {
|
||||
ID: "1250000000",
|
||||
DisplayName: "1250000000",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
opt := &BucketGetObjectVersionsOptions {
|
||||
Delimiter: "/",
|
||||
}
|
||||
res, _, err := client.Bucket.GetObjectVersions(context.Background(), opt)
|
||||
if err != nil {
|
||||
want := &BucketGetObjectVersionsResult{
|
||||
XMLName: xml.Name{Local: "ListVersionsResult"},
|
||||
Name: "examplebucket-1250000000",
|
||||
MaxKeys: 1000,
|
||||
IsTruncated: false,
|
||||
Delimiter: "/",
|
||||
CommonPrefixes: []string{
|
||||
"example-folder-1/",
|
||||
"example-folder-2/",
|
||||
},
|
||||
Version: []ListVersionsResultVersion{
|
||||
{
|
||||
Key: "example-object-1.jpg",
|
||||
VersionId: "MTg0NDUxNzgxMjEzNTU3NTk1Mjg",
|
||||
IsLatest: true,
|
||||
LastModified: "2019-08-16T10:45:53.000Z",
|
||||
ETag: "\"5d1143df07a17b23320d0da161e2819e\"",
|
||||
Size: 30,
|
||||
StorageClass: "STANDARD",
|
||||
Owner: &Owner{
|
||||
ID: "1250000000",
|
||||
DisplayName: "1250000000",
|
||||
},
|
||||
},
|
||||
},
|
||||
DeleteMarker: []ListVersionsResultDeleteMarker{
|
||||
{
|
||||
Key: "example-object-1.jpg",
|
||||
VersionId: "MTg0NDUxNzgxMjEzNjE1OTcxMzM",
|
||||
IsLatest: false,
|
||||
LastModified: "2019-08-16T10:45:47.000Z",
|
||||
Owner: &Owner{
|
||||
ID: "1250000000",
|
||||
DisplayName: "1250000000",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
opt := &BucketGetObjectVersionsOptions{
|
||||
Delimiter: "/",
|
||||
}
|
||||
res, _, err := client.Bucket.GetObjectVersions(context.Background(), opt)
|
||||
if err != nil {
|
||||
t.Fatalf("Bucket.GetObjectVersions returned error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(res, want) {
|
||||
|
||||
36
ci.go
36
ci.go
@@ -31,30 +31,34 @@ func EncodePicOperations(pic *PicOperations) string {
|
||||
}
|
||||
|
||||
type ImageProcessResult struct {
|
||||
XMLName xml.Name `xml:"UploadResult"`
|
||||
OriginalInfo *PicOriginalInfo `xml:"OriginalInfo,omitempty"`
|
||||
ProcessObject *PicProcessObject `xml:"ProcessResults>Object,omitempty"`
|
||||
XMLName xml.Name `xml:"UploadResult"`
|
||||
OriginalInfo *PicOriginalInfo `xml:"OriginalInfo,omitempty"`
|
||||
ProcessResults *PicProcessObject `xml:"ProcessResults>Object,omitempty"`
|
||||
}
|
||||
type PicOriginalInfo struct {
|
||||
Key string `xml:"Key,omitempty"`
|
||||
Location string `xml:"Location,omitempty"`
|
||||
ImageInfo *PicImageInfo `xml:"ImageInfo,omitempty"`
|
||||
ETag string `xml:"ETag,omitempty"`
|
||||
}
|
||||
type PicImageInfo struct {
|
||||
Format string `xml:"Format,omitempty"`
|
||||
Width int `xml:"Width,omitempty"`
|
||||
Height int `xml:"Height,omitempty"`
|
||||
Size int `xml:"Size,omitempty"`
|
||||
Quality int `xml:"Quality,omitempty"`
|
||||
Format string `xml:"Format,omitempty"`
|
||||
Width int `xml:"Width,omitempty"`
|
||||
Height int `xml:"Height,omitempty"`
|
||||
Quality int `xml:"Quality,omitempty"`
|
||||
Ave string `xml:"Ave,omitempty"`
|
||||
Orientation int `xml:"Orientation,omitempty"`
|
||||
}
|
||||
type PicProcessObject struct {
|
||||
Key string `xml:"Key,omitempty"`
|
||||
Location string `xml:"Location,omitempty"`
|
||||
Format string `xml:"Format,omitempty"`
|
||||
Width int `xml:"Width,omitempty"`
|
||||
Height int `xml:"Height,omitempty"`
|
||||
Size int `xml:"Size,omitempty"`
|
||||
Quality int `xml:"Quality,omitempty"`
|
||||
Key string `xml:"Key,omitempty"`
|
||||
Location string `xml:"Location,omitempty"`
|
||||
Format string `xml:"Format,omitempty"`
|
||||
Width int `xml:"Width,omitempty"`
|
||||
Height int `xml:"Height,omitempty"`
|
||||
Size int `xml:"Size,omitempty"`
|
||||
Quality int `xml:"Quality,omitempty"`
|
||||
ETag string `xml:"ETag,omitempty"`
|
||||
WatermarkStatus int `xml:"WatermarkStatus,omitempty"`
|
||||
}
|
||||
|
||||
type picOperationsHeader struct {
|
||||
@@ -171,7 +175,7 @@ type VideoAuditingJobDetail struct {
|
||||
CreationTime string `xml:",omitempty"`
|
||||
Object string `xml:",omitempty"`
|
||||
SnapshotCount string `xml:",omitempty"`
|
||||
result int `xml:",omitempty"`
|
||||
Result int `xml:",omitempty"`
|
||||
PornInfo *RecognitionInfo `xml:",omitempty"`
|
||||
TerrorismInfo *RecognitionInfo `xml:",omitempty"`
|
||||
PoliticsInfo *RecognitionInfo `xml:",omitempty"`
|
||||
|
||||
272
ci_doc.go
Normal file
272
ci_doc.go
Normal file
@@ -0,0 +1,272 @@
|
||||
package cos
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type DocProcessJobInput struct {
|
||||
Object string `xml:"Object,omitempty"`
|
||||
}
|
||||
|
||||
type DocProcessJobOutput struct {
|
||||
Region string `xml:"Region,omitempty"`
|
||||
Bucket string `xml:"Bucket,omitempty"`
|
||||
Object string `xml:"Object,omitempty"`
|
||||
}
|
||||
|
||||
type DocProcessJobDocProcess struct {
|
||||
SrcType string `xml:"SrcType,omitempty"`
|
||||
TgtType string `xml:"TgtType,omitempty"`
|
||||
SheetId int `xml:"SheetId,omitempty"`
|
||||
StartPage int `xml:"StartPage,omitempty"`
|
||||
EndPage int `xml:"EndPage,omitempty"`
|
||||
ImageParams string `xml:"ImageParams,omitempty"`
|
||||
DocPassword string `xml:"DocPassword,omitempty"`
|
||||
Comments int `xml:"Comments,omitempty"`
|
||||
PaperDirection int `xml:"PaperDirection,omitempty"`
|
||||
Quality int `xml:"Quality,omitempty"`
|
||||
Zoom int `xml:"Zoom,omitempty"`
|
||||
}
|
||||
|
||||
type DocProcessJobDocProcessResult struct {
|
||||
FailPageCount int `xml:",omitempty"`
|
||||
SuccPageCount int `xml:"SuccPageCount,omitempty"`
|
||||
TaskId string `xml:"TaskId,omitempty"`
|
||||
TgtType string `xml:"TgtType,omitempty"`
|
||||
TotalPageCount int `xml:"TotalPageCount,omitempty"`
|
||||
PageInfo struct {
|
||||
PageNo int `xml:"PageNo,omitempty"`
|
||||
TgtUri string `xml:"TgtUri,omitempty"`
|
||||
} `xml:"PageInfo,omitempty"`
|
||||
}
|
||||
|
||||
type DocProcessJobOperation struct {
|
||||
Output *DocProcessJobOutput `xml:"Output,omitempty"`
|
||||
DocProcess *DocProcessJobDocProcess `xml:"DocProcess,omitempty"`
|
||||
DocProcessResult *DocProcessJobDocProcessResult `xml:"DocProcessResult,omitempty"`
|
||||
}
|
||||
|
||||
type DocProcessJobDetail struct {
|
||||
Code string `xml:"Code,omitempty"`
|
||||
Message string `xml:"Message,omitempty"`
|
||||
JobId string `xml:"JobId,omitempty"`
|
||||
Tag string `xml:"Tag,omitempty"`
|
||||
State string `xml:"State,omitempty"`
|
||||
CreationTime string `xml:"CreationTime,omitempty"`
|
||||
QueueId string `xml:"QueueId,omitempty"`
|
||||
Input *DocProcessJobInput `xml:"Input,omitempty"`
|
||||
Operation *DocProcessJobOperation `xml:"Operation,omitempty"`
|
||||
}
|
||||
|
||||
type CreateDocProcessJobsOptions struct {
|
||||
XMLName xml.Name `xml:"Request"`
|
||||
Tag string `xml:"Tag,omitempty"`
|
||||
Input *DocProcessJobInput `xml:"Input,omitempty"`
|
||||
Operation *DocProcessJobOperation `xml:"Operation,omitempty"`
|
||||
QueueId string `xml:"QueueId,omitempty"`
|
||||
}
|
||||
|
||||
type CreateDocProcessJobsResult struct {
|
||||
XMLName xml.Name `xml:"Response"`
|
||||
JobsDetail DocProcessJobDetail `xml:"JobsDetail,omitempty"`
|
||||
}
|
||||
|
||||
func (s *CIService) CreateDocProcessJobs(ctx context.Context, opt *CreateDocProcessJobsOptions) (*CreateDocProcessJobsResult, *Response, error) {
|
||||
var res CreateDocProcessJobsResult
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.CIURL,
|
||||
uri: "/doc_jobs",
|
||||
method: http.MethodPost,
|
||||
body: opt,
|
||||
result: &res,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
return &res, resp, err
|
||||
}
|
||||
|
||||
type DescribeDocProcessJobResult struct {
|
||||
XMLName xml.Name `xml:"Response"`
|
||||
JobsDetail *DocProcessJobDetail `xml:"JobsDetail,omitempty"`
|
||||
NonExistJobIds string `xml:"NonExistJobIds,omitempty"`
|
||||
}
|
||||
|
||||
func (s *CIService) DescribeDocProcessJob(ctx context.Context, jobid string) (*DescribeDocProcessJobResult, *Response, error) {
|
||||
var res DescribeDocProcessJobResult
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.CIURL,
|
||||
uri: "/doc_jobs/" + jobid,
|
||||
method: http.MethodGet,
|
||||
result: &res,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
return &res, resp, err
|
||||
}
|
||||
|
||||
type DescribeDocProcessJobsOptions struct {
|
||||
QueueId string `url:"queueId,omitempty"`
|
||||
Tag string `url:"tag,omitempty"`
|
||||
OrderByTime string `url:"orderByTime,omitempty"`
|
||||
NextToken string `url:"nextToken,omitempty"`
|
||||
Size int `url:"size,omitempty"`
|
||||
States string `url:"states,omitempty"`
|
||||
StartCreationTime string `url:"startCreationTime,omitempty"`
|
||||
EndCreationTime string `url:"endCreationTime,omitempty"`
|
||||
}
|
||||
|
||||
type DescribeDocProcessJobsResult struct {
|
||||
XMLName xml.Name `xml:"Response"`
|
||||
JobsDetail []DocProcessJobDetail `xml:"JobsDetail,omitempty"`
|
||||
NextToken string `xml:"NextToken,omitempty"`
|
||||
}
|
||||
|
||||
func (s *CIService) DescribeDocProcessJobs(ctx context.Context, opt *DescribeDocProcessJobsOptions) (*DescribeDocProcessJobsResult, *Response, error) {
|
||||
var res DescribeDocProcessJobsResult
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.CIURL,
|
||||
uri: "/doc_jobs",
|
||||
optQuery: opt,
|
||||
method: http.MethodGet,
|
||||
result: &res,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
return &res, resp, err
|
||||
}
|
||||
|
||||
type DescribeDocProcessQueuesOptions struct {
|
||||
QueueIds string `url:"queueIds,omitempty"`
|
||||
State string `url:"state,omitempty"`
|
||||
PageNumber int `url:"pageNumber,omitempty"`
|
||||
PageSize int `url:"pageSize,omitempty"`
|
||||
}
|
||||
|
||||
type DescribeDocProcessQueuesResult struct {
|
||||
XMLName xml.Name `xml:"Response"`
|
||||
RequestId string `xml:"RequestId,omitempty"`
|
||||
TotalCount int `xml:"TotalCount,omitempty"`
|
||||
PageNumber int `xml:"PageNumber,omitempty"`
|
||||
PageSize int `xml:"PageSize,omitempty"`
|
||||
QueueList []DocProcessQueue `xml:"QueueList,omitempty"`
|
||||
NonExistPIDs []string `xml:"NonExistPIDs,omitempty"`
|
||||
}
|
||||
|
||||
type DocProcessQueue struct {
|
||||
QueueId string `xml:"QueueId,omitempty"`
|
||||
Name string `xml:"Name,omitempty"`
|
||||
State string `xml:"State,omitempty"`
|
||||
MaxSize int `xml:"MaxSize,omitempty"`
|
||||
MaxConcurrent int `xml:"MaxConcurrent,omitempty"`
|
||||
UpdateTime string `xml:"UpdateTime,omitempty"`
|
||||
CreateTime string `xml:"CreateTime,omitempty"`
|
||||
NotifyConfig *DocProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
|
||||
}
|
||||
|
||||
type DocProcessQueueNotifyConfig struct {
|
||||
Url string `xml:"Url,omitempty"`
|
||||
State string `xml:"State,omitempty"`
|
||||
Type string `xml:"Type,omitempty"`
|
||||
Event string `xml:"Event,omitempty"`
|
||||
}
|
||||
|
||||
func (s *CIService) DescribeDocProcessQueues(ctx context.Context, opt *DescribeDocProcessQueuesOptions) (*DescribeDocProcessQueuesResult, *Response, error) {
|
||||
var res DescribeDocProcessQueuesResult
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.CIURL,
|
||||
uri: "/docqueue",
|
||||
optQuery: opt,
|
||||
method: http.MethodGet,
|
||||
result: &res,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
return &res, resp, err
|
||||
}
|
||||
|
||||
type UpdateDocProcessQueueOptions struct {
|
||||
XMLName xml.Name `xml:"Request"`
|
||||
Name string `xml:"Name,omitempty"`
|
||||
QueueID string `xml:"QueueID,omitempty"`
|
||||
State string `xml:"State,omitempty"`
|
||||
NotifyConfig *DocProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateDocProcessQueueResult struct {
|
||||
XMLName xml.Name `xml:"Response"`
|
||||
RequestId string `xml:"RequestId"`
|
||||
Queue *DocProcessQueue `xml:"Queue"`
|
||||
}
|
||||
|
||||
func (s *CIService) UpdateDocProcessQueue(ctx context.Context, opt *UpdateDocProcessQueueOptions) (*UpdateDocProcessQueueResult, *Response, error) {
|
||||
var res UpdateDocProcessQueueResult
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.CIURL,
|
||||
uri: "/docqueue/" + opt.QueueID,
|
||||
body: opt,
|
||||
method: http.MethodPut,
|
||||
result: &res,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
return &res, resp, err
|
||||
}
|
||||
|
||||
type DescribeDocProcessBucketsOptions struct {
|
||||
Regions string `url:"regions,omitempty"`
|
||||
BucketNames string `url:"bucketNames,omitempty"`
|
||||
BucketName string `url:"bucketName,omitempty"`
|
||||
PageNumber int `url:"pageNumber,omitempty"`
|
||||
PageSize int `url:"pageSize,omitempty"`
|
||||
}
|
||||
|
||||
type DescribeDocProcessBucketsResult struct {
|
||||
XMLName xml.Name `xml:"Response"`
|
||||
RequestId string `xml:"RequestId,omitempty"`
|
||||
TotalCount int `xml:"TotalCount,omitempty"`
|
||||
PageNumber int `xml:"PageNumber,omitempty"`
|
||||
PageSize int `xml:"PageSize,omitempty"`
|
||||
DocBucketList []DocProcessBucket `xml:"DocBucketList,omitempty"`
|
||||
}
|
||||
type DocProcessBucket struct {
|
||||
BucketId string `xml:"BucketId,omitempty"`
|
||||
Name string `xml:"Name,omitempty"`
|
||||
Region string `xml:"Region,omitempty"`
|
||||
CreateTime string `xml:"CreateTime,omitempty"`
|
||||
AliasBucketId string `xml:"AliasBucketId,omitempty"`
|
||||
}
|
||||
|
||||
func (s *CIService) DescribeDocProcessBuckets(ctx context.Context, opt *DescribeDocProcessBucketsOptions) (*DescribeDocProcessBucketsResult, *Response, error) {
|
||||
var res DescribeDocProcessBucketsResult
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.CIURL,
|
||||
uri: "/docbucket",
|
||||
optQuery: opt,
|
||||
method: http.MethodGet,
|
||||
result: &res,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
return &res, resp, err
|
||||
}
|
||||
|
||||
type DocPreviewOptions struct {
|
||||
SrcType string `url:"srcType,omitempty"`
|
||||
Page int `url:"page,omitempty"`
|
||||
ImageParams string `url:"ImageParams,omitempty"`
|
||||
Sheet int `url:"sheet,omitempty"`
|
||||
DstType string `url:"dstType,omitempty"`
|
||||
Password string `url:"password,omitempty"`
|
||||
Comment int `url:"comment,omitempty"`
|
||||
ExcelPaperDirection int `url:"excelPaperDirection,omitempty"`
|
||||
Quality int `url:"quality,omitempty"`
|
||||
Zoom int `url:"zoom,omitempty"`
|
||||
}
|
||||
|
||||
func (s *CIService) DocPreview(ctx context.Context, name string, opt *DocPreviewOptions) (*Response, error) {
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.BucketURL,
|
||||
uri: "/" + encodeURIComponent(name) + "?ci-process=doc-preview",
|
||||
optQuery: opt,
|
||||
method: http.MethodGet,
|
||||
disableCloseBody: true,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
return resp, err
|
||||
}
|
||||
2
cos.go
2
cos.go
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
const (
|
||||
// Version current go sdk version
|
||||
Version = "0.7.12"
|
||||
Version = "0.7.16"
|
||||
userAgent = "cos-go-sdk-v5/" + Version
|
||||
contentTypeXML = "application/xml"
|
||||
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
|
||||
|
||||
@@ -226,6 +226,7 @@ func (s *CosTestSuite) TestVersionAndReplication() {
|
||||
}
|
||||
_, err := s.Client.Bucket.PutVersioning(context.Background(), opt)
|
||||
assert.Nil(s.T(), err, "PutVersioning Failed")
|
||||
time.Sleep(time.Second)
|
||||
v, _, err := s.Client.Bucket.GetVersioning(context.Background())
|
||||
assert.Nil(s.T(), err, "GetVersioning Failed")
|
||||
assert.Equal(s.T(), "Enabled", v.Status, "Get Wrong Version status")
|
||||
@@ -248,6 +249,7 @@ func (s *CosTestSuite) TestVersionAndReplication() {
|
||||
|
||||
_, err = s.Client.Bucket.PutBucketReplication(context.Background(), repOpt)
|
||||
assert.Nil(s.T(), err, "PutBucketReplication Failed")
|
||||
time.Sleep(time.Second)
|
||||
vr, _, err := s.Client.Bucket.GetBucketReplication(context.Background())
|
||||
assert.Nil(s.T(), err, "GetBucketReplication Failed")
|
||||
for _, r := range vr.Rule {
|
||||
@@ -880,6 +882,31 @@ func (s *CosTestSuite) TestReferer() {
|
||||
assert.Equal(s.T(), opt.EmptyReferConfiguration, res.EmptyReferConfiguration, "GetReferer Failed")
|
||||
}
|
||||
|
||||
func (s *CosTestSuite) TestAccelerate() {
|
||||
opt := &cos.BucketPutAccelerateOptions{
|
||||
Status: "Enabled",
|
||||
Type: "COS",
|
||||
}
|
||||
_, err := s.Client.Bucket.PutAccelerate(context.Background(), opt)
|
||||
assert.Nil(s.T(), err, "PutAccelerate Failed")
|
||||
|
||||
time.Sleep(time.Second)
|
||||
res, _, err := s.Client.Bucket.GetAccelerate(context.Background())
|
||||
assert.Nil(s.T(), err, "GetAccelerate Failed")
|
||||
assert.Equal(s.T(), opt.Status, res.Status, "GetAccelerate Failed")
|
||||
assert.Equal(s.T(), opt.Type, res.Type, "GetAccelerate Failed")
|
||||
|
||||
opt.Status = "Suspended"
|
||||
_, err = s.Client.Bucket.PutAccelerate(context.Background(), opt)
|
||||
assert.Nil(s.T(), err, "PutAccelerate Failed")
|
||||
|
||||
time.Sleep(time.Second)
|
||||
res, _, err = s.Client.Bucket.GetAccelerate(context.Background())
|
||||
assert.Nil(s.T(), err, "GetAccelerate Failed")
|
||||
assert.Equal(s.T(), opt.Status, res.Status, "GetAccelerate Failed")
|
||||
assert.Equal(s.T(), opt.Type, res.Type, "GetAccelerate Failed")
|
||||
}
|
||||
|
||||
// End of api test
|
||||
|
||||
// All methods that begin with "Test" are run as tests within a
|
||||
|
||||
72
example/bucket/accelerate.go
Normal file
72
example/bucket/accelerate.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func log_status(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if cos.IsNotFoundError(err) {
|
||||
// WARN
|
||||
fmt.Println("Resource is not existed")
|
||||
} else if e, ok := cos.IsCOSError(err); ok {
|
||||
fmt.Printf("Code: %v\n", e.Code)
|
||||
fmt.Printf("Message: %v\n", e.Message)
|
||||
fmt.Printf("Resource: %v\n", e.Resource)
|
||||
fmt.Printf("RequestId: %v\n", e.RequestID)
|
||||
// ERROR
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
// ERROR
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
res, _, err := c.Bucket.GetAccelerate(context.Background())
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", res)
|
||||
|
||||
opt := &cos.BucketPutAccelerateOptions{
|
||||
Status: "Enabled",
|
||||
Type: "COS",
|
||||
}
|
||||
_, err = c.Bucket.PutAccelerate(context.Background(), opt)
|
||||
log_status(err)
|
||||
|
||||
res, _, err = c.Bucket.GetAccelerate(context.Background())
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", res)
|
||||
|
||||
opt.Status = "Suspended"
|
||||
_, err = c.Bucket.PutAccelerate(context.Background(), opt)
|
||||
log_status(err)
|
||||
|
||||
res, _, err = c.Bucket.GetAccelerate(context.Background())
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", res)
|
||||
}
|
||||
@@ -48,13 +48,13 @@ func main() {
|
||||
},
|
||||
})
|
||||
|
||||
opt := &cos.BucketPutIntelligentTieringOptions {
|
||||
Status: "Enabled",
|
||||
Transition: &cos.BucketIntelligentTieringTransition {
|
||||
Days: 30,
|
||||
},
|
||||
}
|
||||
_, err := c.Bucket.PutIntelligentTiering(context.Background(), opt)
|
||||
opt := &cos.BucketPutIntelligentTieringOptions{
|
||||
Status: "Enabled",
|
||||
Transition: &cos.BucketIntelligentTieringTransition{
|
||||
Days: 30,
|
||||
},
|
||||
}
|
||||
_, err := c.Bucket.PutIntelligentTiering(context.Background(), opt)
|
||||
log_status(err)
|
||||
res, _, err := c.Bucket.GetIntelligentTiering(context.Background())
|
||||
log_status(err)
|
||||
|
||||
132
example/object/ci_doc_process.go
Normal file
132
example/object/ci_doc_process.go
Normal file
@@ -0,0 +1,132 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func log_status(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if cos.IsNotFoundError(err) {
|
||||
// WARN
|
||||
fmt.Println("WARN: Resource is not existed")
|
||||
} else if e, ok := cos.IsCOSError(err); ok {
|
||||
fmt.Printf("ERROR: Code: %v\n", e.Code)
|
||||
fmt.Printf("ERROR: Message: %v\n", e.Message)
|
||||
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
|
||||
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
|
||||
// ERROR
|
||||
} else {
|
||||
fmt.Printf("ERROR: %v\n", err)
|
||||
// ERROR
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
|
||||
cu, _ := url.Parse("https://test-1259654469.ci.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
// Notice when put a large file and set need the request body, might happend out of memory error.
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// 1、UpdateDocProcessQueue
|
||||
updateQueueOpt := &cos.UpdateDocProcessQueueOptions{
|
||||
Name: "queue-doc-process-1",
|
||||
QueueID: "p111a8dd208104ce3b11c78398f658ca8",
|
||||
State: "Active",
|
||||
NotifyConfig: &cos.DocProcessQueueNotifyConfig{
|
||||
State: "Off",
|
||||
},
|
||||
}
|
||||
updateQueueRes, _, err := c.CI.UpdateDocProcessQueue(context.Background(), updateQueueOpt)
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", updateQueueRes)
|
||||
|
||||
// 2、DescribeDocProcessQueues
|
||||
DescribeQueueOpt := &cos.DescribeDocProcessQueuesOptions{
|
||||
QueueIds: "p111a8dd208104ce3b11c78398f658ca8,p4318f85d2aa14c43b1dba6f9b78be9b3,aacb2bb066e9c4478834d4196e76c49d3",
|
||||
PageNumber: 1,
|
||||
PageSize: 2,
|
||||
}
|
||||
DescribeQueueRes, _, err := c.CI.DescribeDocProcessQueues(context.Background(), DescribeQueueOpt)
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", DescribeQueueRes)
|
||||
|
||||
// 3、DescribeDocProcessBuckets
|
||||
BucketsOpt := &cos.DescribeDocProcessBucketsOptions{
|
||||
Regions: "All",
|
||||
}
|
||||
BucketsRes, _, err := c.CI.DescribeDocProcessBuckets(context.Background(), BucketsOpt)
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", BucketsRes)
|
||||
|
||||
// 4、CreateDocProcessJobs
|
||||
createJobOpt := &cos.CreateDocProcessJobsOptions{
|
||||
Tag: "DocProcess",
|
||||
Input: &cos.DocProcessJobInput{
|
||||
Object: "form.pdf",
|
||||
},
|
||||
Operation: &cos.DocProcessJobOperation{
|
||||
Output: &cos.DocProcessJobOutput{
|
||||
Region: "ap-guangzhou",
|
||||
Object: "test-doc${Number}",
|
||||
Bucket: "test-1259654469",
|
||||
},
|
||||
DocProcess: &cos.DocProcessJobDocProcess{
|
||||
TgtType: "png",
|
||||
StartPage: 1,
|
||||
EndPage: -1,
|
||||
ImageParams: "watermark/1/image/aHR0cDovL3Rlc3QwMDUtMTI1MTcwNDcwOC5jb3MuYXAtY2hvbmdxaW5nLm15cWNsb3VkLmNvbS8xLmpwZw==/gravity/southeast",
|
||||
},
|
||||
},
|
||||
QueueId: "p111a8dd208104ce3b11c78398f658ca8",
|
||||
}
|
||||
createJobRes, _, err := c.CI.CreateDocProcessJobs(context.Background(), createJobOpt)
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", createJobRes.JobsDetail)
|
||||
|
||||
// 5、DescribeDocProcessJob
|
||||
DescribeJobRes, _, err := c.CI.DescribeDocProcessJob(context.Background(), createJobRes.JobsDetail.JobId)
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", DescribeJobRes.JobsDetail)
|
||||
|
||||
// 6、DescribeDocProcessJobs
|
||||
DescribeJobsOpt := &cos.DescribeDocProcessJobsOptions{
|
||||
QueueId: "p111a8dd208104ce3b11c78398f658ca8",
|
||||
Tag: "DocProcess",
|
||||
}
|
||||
DescribeJobsRes, _, err := c.CI.DescribeDocProcessJobs(context.Background(), DescribeJobsOpt)
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", DescribeJobsRes)
|
||||
|
||||
// 7、doc-preview
|
||||
opt := &cos.DocPreviewOptions{
|
||||
Page: 1,
|
||||
}
|
||||
resp, err := c.CI.DocPreview(context.Background(), "form.pdf", opt)
|
||||
log_status(err)
|
||||
fd, _ := os.OpenFile("form.pdf", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0660)
|
||||
io.Copy(fd, resp.Body)
|
||||
fd.Close()
|
||||
|
||||
}
|
||||
@@ -19,7 +19,7 @@ func log_status(err error) {
|
||||
}
|
||||
if cos.IsNotFoundError(err) {
|
||||
// WARN
|
||||
fmt.Println("WARN: Resource is not existed")
|
||||
fmt.Println("WARN: Resource is not existed")
|
||||
} else if e, ok := cos.IsCOSError(err); ok {
|
||||
fmt.Printf("ERROR: Code: %v\n", e.Code)
|
||||
fmt.Printf("ERROR: Message: %v\n", e.Message)
|
||||
@@ -33,7 +33,7 @@ func log_status(err error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{BucketURL: u}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
@@ -48,8 +48,8 @@ func main() {
|
||||
},
|
||||
})
|
||||
|
||||
// Case1 Download object into ReadCloser(). the body needs to be closed
|
||||
name := "test/hello.txt"
|
||||
// Case1 通过resp.Body下载对象,Body需要关闭
|
||||
name := "test/example"
|
||||
resp, err := c.Object.Get(context.Background(), name, nil)
|
||||
log_status(err)
|
||||
|
||||
@@ -57,8 +57,8 @@ func main() {
|
||||
resp.Body.Close()
|
||||
fmt.Printf("%s\n", string(bs))
|
||||
|
||||
// Case2 Download object to local file. the body needs to be closed
|
||||
fd, err := os.OpenFile("hello.txt", os.O_WRONLY|os.O_CREATE, 0660)
|
||||
// Case2 下载对象到文件. Body需要关闭
|
||||
fd, err := os.OpenFile("test", os.O_WRONLY|os.O_CREATE, 0660)
|
||||
log_status(err)
|
||||
|
||||
defer fd.Close()
|
||||
@@ -68,11 +68,11 @@ func main() {
|
||||
io.Copy(fd, resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
// Case3 Download object to local file path
|
||||
_, err = c.Object.GetToFile(context.Background(), name, "hello_1.txt", nil)
|
||||
// Case3 下载对象到文件
|
||||
_, err = c.Object.GetToFile(context.Background(), name, "test", nil)
|
||||
log_status(err)
|
||||
|
||||
// Case4 Download object with range header, can used to concurrent download
|
||||
// Case4 range下载对象,可以根据range实现并发下载
|
||||
opt := &cos.ObjectGetOptions{
|
||||
ResponseContentType: "text/html",
|
||||
Range: "bytes=0-3",
|
||||
@@ -82,4 +82,11 @@ func main() {
|
||||
bs, _ = ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
fmt.Printf("%s\n", string(bs))
|
||||
|
||||
// Case5 下载对象到文件,查看下载进度
|
||||
opt = &cos.ObjectGetOptions{
|
||||
Listener: &cos.DefaultProgressListener{},
|
||||
}
|
||||
_, err = c.Object.GetToFile(context.Background(), name, "test", opt)
|
||||
log_status(err)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func log_status(err error) {
|
||||
}
|
||||
if cos.IsNotFoundError(err) {
|
||||
// WARN
|
||||
fmt.Println("WARN: Resource is not existed")
|
||||
fmt.Println("WARN: Resource is not existed")
|
||||
} else if e, ok := cos.IsCOSError(err); ok {
|
||||
fmt.Printf("ERROR: Code: %v\n", e.Code)
|
||||
fmt.Printf("ERROR: Message: %v\n", e.Message)
|
||||
@@ -44,20 +44,19 @@ func main() {
|
||||
// Notice when put a large file and set need the request body, might happend out of memory error.
|
||||
RequestBody: false,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
ResponseBody: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// Case1 normal put object
|
||||
name := "test/objectPut.go"
|
||||
// Case1 上传对象
|
||||
name := "test/example"
|
||||
f := strings.NewReader("test")
|
||||
|
||||
_, err := c.Object.Put(context.Background(), name, f, nil)
|
||||
log_status(err)
|
||||
|
||||
// Case2 put object with the options
|
||||
name = "test/put_option.go"
|
||||
// Case2 使用options上传对象
|
||||
f = strings.NewReader("test xxx")
|
||||
opt := &cos.ObjectPutOptions{
|
||||
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
|
||||
@@ -71,7 +70,11 @@ func main() {
|
||||
_, err = c.Object.Put(context.Background(), name, f, opt)
|
||||
log_status(err)
|
||||
|
||||
// Case3 put object by local file path
|
||||
// Case3 通过本地文件上传对象
|
||||
_, err = c.Object.PutFromFile(context.Background(), name, "./test", nil)
|
||||
log_status(err)
|
||||
|
||||
// Case4 查看上传进度
|
||||
opt.ObjectPutHeaderOptions.Listener = &cos.DefaultProgressListener{}
|
||||
_, err = c.Object.PutFromFile(context.Background(), name, "./test", opt)
|
||||
}
|
||||
|
||||
59
example/object/put_with_timeout.go
Normal file
59
example/object/put_with_timeout.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func log_status(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if cos.IsNotFoundError(err) {
|
||||
// WARN
|
||||
fmt.Println("WARN: Resource is not existed")
|
||||
} else if e, ok := cos.IsCOSError(err); ok {
|
||||
fmt.Printf("ERROR: Code: %v\n", e.Code)
|
||||
fmt.Printf("ERROR: Message: %v\n", e.Message)
|
||||
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
|
||||
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
|
||||
// ERROR
|
||||
} else {
|
||||
fmt.Printf("ERROR: %v\n", err)
|
||||
// ERROR
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{BucketURL: u}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
// Notice when put a large file and set need the request body, might happend out of memory error.
|
||||
RequestBody: false,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: false,
|
||||
},
|
||||
},
|
||||
Timeout: 5 * time.Second, // HTTP超时时间
|
||||
})
|
||||
|
||||
// Case1 上传对象
|
||||
name := "test/example"
|
||||
// Case3 通过本地文件上传对象
|
||||
ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) // context超时时间
|
||||
_, err := c.Object.PutFromFile(ctx, name, "./test", nil) // 请求的超时时间为 min{context超时时间, HTTP超时时间}
|
||||
log_status(err)
|
||||
}
|
||||
@@ -49,9 +49,26 @@ func main() {
|
||||
},
|
||||
})
|
||||
|
||||
// Case1 多线程上传对象
|
||||
opt := &cos.MultiUploadOptions{
|
||||
ThreadPoolSize: 3,
|
||||
}
|
||||
v, _, err := c.Object.Upload(
|
||||
context.Background(), "gomulput1G", "./test1G", nil,
|
||||
context.Background(), "gomulput1G", "./test1G", opt,
|
||||
)
|
||||
log_status(err)
|
||||
fmt.Println(v)
|
||||
fmt.Printf("Case1 done, %v\n", v)
|
||||
|
||||
// Case2 多线程上传对象,查看上传进度
|
||||
opt.OptIni = &cos.InitiateMultipartUploadOptions{
|
||||
nil,
|
||||
&cos.ObjectPutHeaderOptions{
|
||||
Listener: &cos.DefaultProgressListener{},
|
||||
},
|
||||
}
|
||||
v, _, err = c.Object.Upload(
|
||||
context.Background(), "gomulput1G", "./test1G", opt,
|
||||
)
|
||||
log_status(err)
|
||||
fmt.Printf("Case2 done, %v\n", v)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func initUpload(c *cos.Client, name string) *cos.InitiateMultipartUploadResult {
|
||||
}
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{BucketURL: u}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
@@ -49,20 +49,50 @@ func main() {
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
RequestBody: false,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
ResponseBody: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
optcom := &cos.CompleteMultipartUploadOptions{}
|
||||
name := "test/test_multi_upload.go"
|
||||
up := initUpload(c, name)
|
||||
uploadID := up.UploadID
|
||||
|
||||
f := strings.NewReader("test heoo")
|
||||
_, err := c.Object.UploadPart(
|
||||
context.Background(), name, uploadID, 1, f, nil,
|
||||
fd, err := os.Open("test")
|
||||
if err != nil {
|
||||
fmt.Printf("Open File Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer fd.Close()
|
||||
stat, err := fd.Stat()
|
||||
if err != nil {
|
||||
fmt.Printf("Stat File Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
opt := &cos.ObjectUploadPartOptions{
|
||||
Listener: &cos.DefaultProgressListener{},
|
||||
ContentLength: int(stat.Size()),
|
||||
}
|
||||
resp, err := c.Object.UploadPart(
|
||||
context.Background(), name, uploadID, 1, fd, opt,
|
||||
)
|
||||
log_status(err)
|
||||
optcom.Parts = append(optcom.Parts, cos.Object{
|
||||
PartNumber: 1, ETag: resp.Header.Get("ETag"),
|
||||
})
|
||||
|
||||
f := strings.NewReader("test heoo")
|
||||
resp, err = c.Object.UploadPart(
|
||||
context.Background(), name, uploadID, 2, f, nil,
|
||||
)
|
||||
log_status(err)
|
||||
optcom.Parts = append(optcom.Parts, cos.Object{
|
||||
PartNumber: 2, ETag: resp.Header.Get("ETag"),
|
||||
})
|
||||
|
||||
_, _, err = c.Object.CompleteMultipartUpload(context.Background(), name, uploadID, optcom)
|
||||
log_status(err)
|
||||
}
|
||||
|
||||
40
helper.go
40
helper.go
@@ -4,11 +4,18 @@ import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"crypto/sha1"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 单次上传文件最大为5GB
|
||||
const singleUploadMaxLength = 5 * 1024 * 1024 * 1024
|
||||
|
||||
// 计算 md5 或 sha1 时的分块大小
|
||||
const calDigestBlockSize = 1024 * 1024 * 10
|
||||
|
||||
@@ -112,3 +119,36 @@ func DecodeURIComponent(s string) (string, error) {
|
||||
func EncodeURIComponent(s string) string {
|
||||
return encodeURIComponent(s)
|
||||
}
|
||||
|
||||
func GetReaderLen(reader io.Reader) (length int64, err error) {
|
||||
switch v := reader.(type) {
|
||||
case *bytes.Buffer:
|
||||
length = int64(v.Len())
|
||||
case *bytes.Reader:
|
||||
length = int64(v.Len())
|
||||
case *strings.Reader:
|
||||
length = int64(v.Len())
|
||||
case *os.File:
|
||||
stat, ferr := v.Stat()
|
||||
if ferr != nil {
|
||||
err = fmt.Errorf("can't get reader length: %s", ferr.Error())
|
||||
} else {
|
||||
length = stat.Size()
|
||||
}
|
||||
case *io.LimitedReader:
|
||||
length = int64(v.N)
|
||||
case FixedLengthReader:
|
||||
length = v.Size()
|
||||
default:
|
||||
err = fmt.Errorf("can't get reader content length, unkown reader type")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func CheckReaderLen(reader io.Reader) error {
|
||||
nlen, err := GetReaderLen(reader)
|
||||
if err != nil || nlen < singleUploadMaxLength {
|
||||
return nil
|
||||
}
|
||||
return errors.New("The single object size you upload can not be larger than 5GB")
|
||||
}
|
||||
|
||||
113
object.go
113
object.go
@@ -12,6 +12,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -35,6 +36,9 @@ type ObjectGetOptions struct {
|
||||
XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"`
|
||||
|
||||
XCosTrafficLimit int `header:"x-cos-traffic-limit,omitempty" url:"-" xml:"-"`
|
||||
|
||||
// 下载进度, ProgressCompleteEvent不能表示对应API调用成功,API是否调用成功的判断标准为返回err==nil
|
||||
Listener ProgressListener `header:"-" url:"-" xml:"-"`
|
||||
}
|
||||
|
||||
// presignedURLTestingOptions is the opt of presigned url
|
||||
@@ -65,6 +69,14 @@ func (s *ObjectService) Get(ctx context.Context, name string, opt *ObjectGetOpti
|
||||
disableCloseBody: true,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
|
||||
if opt != nil && opt.Listener != nil {
|
||||
if err == nil && resp != nil {
|
||||
if totalBytes, e := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64); e == nil {
|
||||
resp.Body = TeeReader(resp.Body, nil, totalBytes, opt.Listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -115,7 +127,7 @@ func (s *ObjectService) GetPresignedURL(ctx context.Context, httpMethod, name, a
|
||||
authTime = NewAuthTime(expired)
|
||||
}
|
||||
authorization := newAuthorization(ak, sk, req, authTime)
|
||||
sign := encodeURIComponent(authorization, []byte{'&','='})
|
||||
sign := encodeURIComponent(authorization, []byte{'&', '='})
|
||||
|
||||
if req.URL.RawQuery == "" {
|
||||
req.URL.RawQuery = fmt.Sprintf("%s", sign)
|
||||
@@ -152,6 +164,9 @@ type ObjectPutHeaderOptions struct {
|
||||
//兼容其他自定义头部
|
||||
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
|
||||
XCosTrafficLimit int `header:"x-cos-traffic-limit,omitempty" url:"-" xml:"-"`
|
||||
|
||||
// 上传进度, ProgressCompleteEvent不能表示对应API调用成功,API是否调用成功的判断标准为返回err==nil
|
||||
Listener ProgressListener `header:"-" url:"-" xml:"-"`
|
||||
}
|
||||
|
||||
// ObjectPutOptions the options of put object
|
||||
@@ -166,6 +181,17 @@ type ObjectPutOptions struct {
|
||||
//
|
||||
// https://www.qcloud.com/document/product/436/7749
|
||||
func (s *ObjectService) Put(ctx context.Context, name string, r io.Reader, opt *ObjectPutOptions) (*Response, error) {
|
||||
if err := CheckReaderLen(r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opt != nil && opt.Listener != nil {
|
||||
totalBytes, err := GetReaderLen(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r = TeeReader(r, nil, totalBytes, opt.Listener)
|
||||
}
|
||||
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.BucketURL,
|
||||
uri: "/" + encodeURIComponent(name),
|
||||
@@ -174,6 +200,7 @@ func (s *ObjectService) Put(ctx context.Context, name string, r io.Reader, opt *
|
||||
optHeader: opt,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -571,27 +598,27 @@ func DividePart(fileSize int64) (int64, int64) {
|
||||
return partNum, partSize
|
||||
}
|
||||
|
||||
func SplitFileIntoChunks(filePath string, partSize int64) ([]Chunk, int, error) {
|
||||
func SplitFileIntoChunks(filePath string, partSize int64) (int64, []Chunk, int, error) {
|
||||
if filePath == "" {
|
||||
return nil, 0, errors.New("filePath invalid")
|
||||
return 0, nil, 0, errors.New("filePath invalid")
|
||||
}
|
||||
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return 0, nil, 0, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
stat, err := file.Stat()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return 0, nil, 0, err
|
||||
}
|
||||
var partNum int64
|
||||
if partSize > 0 {
|
||||
partSize = partSize * 1024 * 1024
|
||||
partNum = stat.Size() / partSize
|
||||
if partNum >= 10000 {
|
||||
return nil, 0, errors.New("Too many parts, out of 10000")
|
||||
return 0, nil, 0, errors.New("Too many parts, out of 10000")
|
||||
}
|
||||
} else {
|
||||
partNum, partSize = DividePart(stat.Size())
|
||||
@@ -614,7 +641,7 @@ func SplitFileIntoChunks(filePath string, partSize int64) ([]Chunk, int, error)
|
||||
partNum++
|
||||
}
|
||||
|
||||
return chunks, int(partNum), nil
|
||||
return int64(stat.Size()), chunks, int(partNum), nil
|
||||
|
||||
}
|
||||
|
||||
@@ -707,7 +734,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
|
||||
opt = &MultiUploadOptions{}
|
||||
}
|
||||
// 1.Get the file chunk
|
||||
chunks, partNum, err := SplitFileIntoChunks(filepath, opt.PartSize)
|
||||
totalBytes, chunks, partNum, err := SplitFileIntoChunks(filepath, opt.PartSize)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -768,29 +795,40 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
|
||||
go worker(s, chjobs, chresults)
|
||||
}
|
||||
|
||||
// 4.Push jobs
|
||||
for _, chunk := range chunks {
|
||||
if chunk.Done {
|
||||
continue
|
||||
}
|
||||
partOpt := &ObjectUploadPartOptions{}
|
||||
if optini != nil && optini.ObjectPutHeaderOptions != nil {
|
||||
partOpt.XCosSSECustomerAglo = optini.XCosSSECustomerAglo
|
||||
partOpt.XCosSSECustomerKey = optini.XCosSSECustomerKey
|
||||
partOpt.XCosSSECustomerKeyMD5 = optini.XCosSSECustomerKeyMD5
|
||||
partOpt.XCosTrafficLimit = optini.XCosTrafficLimit
|
||||
}
|
||||
job := &Jobs{
|
||||
Name: name,
|
||||
RetryTimes: 3,
|
||||
FilePath: filepath,
|
||||
UploadId: uploadID,
|
||||
Chunk: chunk,
|
||||
Opt: partOpt,
|
||||
}
|
||||
chjobs <- job
|
||||
// progress started event
|
||||
var listener ProgressListener
|
||||
var consumedBytes int64
|
||||
if opt.OptIni != nil {
|
||||
listener = opt.OptIni.Listener
|
||||
}
|
||||
close(chjobs)
|
||||
event := newProgressEvent(ProgressStartedEvent, 0, 0, totalBytes)
|
||||
progressCallback(listener, event)
|
||||
|
||||
// 4.Push jobs
|
||||
go func() {
|
||||
for _, chunk := range chunks {
|
||||
if chunk.Done {
|
||||
continue
|
||||
}
|
||||
partOpt := &ObjectUploadPartOptions{}
|
||||
if optini != nil && optini.ObjectPutHeaderOptions != nil {
|
||||
partOpt.XCosSSECustomerAglo = optini.XCosSSECustomerAglo
|
||||
partOpt.XCosSSECustomerKey = optini.XCosSSECustomerKey
|
||||
partOpt.XCosSSECustomerKeyMD5 = optini.XCosSSECustomerKeyMD5
|
||||
partOpt.XCosTrafficLimit = optini.XCosTrafficLimit
|
||||
}
|
||||
job := &Jobs{
|
||||
Name: name,
|
||||
RetryTimes: 3,
|
||||
FilePath: filepath,
|
||||
UploadId: uploadID,
|
||||
Chunk: chunk,
|
||||
Opt: partOpt,
|
||||
}
|
||||
chjobs <- job
|
||||
}
|
||||
close(chjobs)
|
||||
}()
|
||||
|
||||
// 5.Recv the resp etag to complete
|
||||
for i := 0; i < partNum; i++ {
|
||||
@@ -798,22 +836,35 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
|
||||
optcom.Parts = append(optcom.Parts, Object{
|
||||
PartNumber: chunks[i].Number, ETag: chunks[i].ETag},
|
||||
)
|
||||
consumedBytes += chunks[i].Size
|
||||
event = newProgressEvent(ProgressDataEvent, chunks[i].Size, consumedBytes, totalBytes)
|
||||
progressCallback(listener, event)
|
||||
continue
|
||||
}
|
||||
res := <-chresults
|
||||
// Notice one part fail can not get the etag according.
|
||||
if res.Resp == nil || res.err != nil {
|
||||
// Some part already fail, can not to get the header inside.
|
||||
return nil, nil, fmt.Errorf("UploadID %s, part %d failed to get resp content. error: %s", uploadID, res.PartNumber, res.err.Error())
|
||||
err := fmt.Errorf("UploadID %s, part %d failed to get resp content. error: %s", uploadID, res.PartNumber, res.err.Error())
|
||||
event = newProgressEvent(ProgressFailedEvent, 0, consumedBytes, totalBytes, err)
|
||||
progressCallback(listener, event)
|
||||
return nil, nil, err
|
||||
}
|
||||
// Notice one part fail can not get the etag according.
|
||||
etag := res.Resp.Header.Get("ETag")
|
||||
optcom.Parts = append(optcom.Parts, Object{
|
||||
PartNumber: res.PartNumber, ETag: etag},
|
||||
)
|
||||
consumedBytes += chunks[res.PartNumber-1].Size
|
||||
event = newProgressEvent(ProgressDataEvent, chunks[res.PartNumber-1].Size, consumedBytes, totalBytes)
|
||||
progressCallback(listener, event)
|
||||
}
|
||||
close(chresults)
|
||||
sort.Sort(ObjectList(optcom.Parts))
|
||||
|
||||
event = newProgressEvent(ProgressCompletedEvent, 0, consumedBytes, totalBytes)
|
||||
progressCallback(listener, event)
|
||||
|
||||
v, resp, err := s.CompleteMultipartUpload(context.Background(), name, uploadID, optcom)
|
||||
|
||||
return v, resp, err
|
||||
|
||||
@@ -41,15 +41,19 @@ func (s *ObjectService) InitiateMultipartUpload(ctx context.Context, name string
|
||||
|
||||
// ObjectUploadPartOptions is the options of upload-part
|
||||
type ObjectUploadPartOptions struct {
|
||||
Expect string `header:"Expect,omitempty" url:"-"`
|
||||
XCosContentSHA1 string `header:"x-cos-content-sha1,omitempty" url:"-"`
|
||||
ContentLength int `header:"Content-Length,omitempty" url:"-"`
|
||||
|
||||
Expect string `header:"Expect,omitempty" url:"-"`
|
||||
XCosContentSHA1 string `header:"x-cos-content-sha1,omitempty" url:"-"`
|
||||
ContentLength int `header:"Content-Length,omitempty" url:"-"`
|
||||
ContentMD5 string `header:"Content-MD5,omitempty" url:"-"`
|
||||
XCosSSECustomerAglo string `header:"x-cos-server-side-encryption-customer-algorithm,omitempty" url:"-" xml:"-"`
|
||||
XCosSSECustomerKey string `header:"x-cos-server-side-encryption-customer-key,omitempty" url:"-" xml:"-"`
|
||||
XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"`
|
||||
|
||||
XCosTrafficLimit int `header:"x-cos-traffic-limit,omitempty" url:"-" xml:"-"`
|
||||
|
||||
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
|
||||
// 上传进度, ProgressCompleteEvent不能表示对应API调用成功,API是否调用成功的判断标准为返回err==nil
|
||||
Listener ProgressListener `header:"-" url:"-" xml:"-"`
|
||||
}
|
||||
|
||||
// UploadPart 请求实现在初始化以后的分块上传,支持的块的数量为1到10000,块的大小为1 MB 到5 GB。
|
||||
@@ -61,6 +65,16 @@ type ObjectUploadPartOptions struct {
|
||||
//
|
||||
// https://www.qcloud.com/document/product/436/7750
|
||||
func (s *ObjectService) UploadPart(ctx context.Context, name, uploadID string, partNumber int, r io.Reader, opt *ObjectUploadPartOptions) (*Response, error) {
|
||||
if err := CheckReaderLen(r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opt != nil && opt.Listener != nil {
|
||||
totalBytes, err := GetReaderLen(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r = TeeReader(r, nil, totalBytes, opt.Listener)
|
||||
}
|
||||
u := fmt.Sprintf("/%s?partNumber=%d&uploadId=%s", encodeURIComponent(name), partNumber, uploadID)
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.BucketURL,
|
||||
|
||||
@@ -129,7 +129,7 @@ func TestObjectService_Options(t *testing.T) {
|
||||
})
|
||||
|
||||
opt := &ObjectOptionsOptions{
|
||||
Origin: "www.qq.com",
|
||||
Origin: "www.qq.com",
|
||||
AccessControlRequestMethod: "PUT",
|
||||
}
|
||||
|
||||
|
||||
139
progress.go
Normal file
139
progress.go
Normal file
@@ -0,0 +1,139 @@
|
||||
package cos
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ProgressEventType int
|
||||
|
||||
const (
|
||||
// 数据开始传输
|
||||
ProgressStartedEvent ProgressEventType = iota
|
||||
// 数据传输中
|
||||
ProgressDataEvent
|
||||
// 数据传输完成, 但不能表示对应API调用完成
|
||||
ProgressCompletedEvent
|
||||
// 只有在数据传输时发生错误才会返回
|
||||
ProgressFailedEvent
|
||||
)
|
||||
|
||||
type ProgressEvent struct {
|
||||
EventType ProgressEventType
|
||||
RWBytes int64
|
||||
ConsumedBytes int64
|
||||
TotalBytes int64
|
||||
Err error
|
||||
}
|
||||
|
||||
func newProgressEvent(eventType ProgressEventType, rwBytes, consumed, total int64, err ...error) *ProgressEvent {
|
||||
event := &ProgressEvent{
|
||||
EventType: eventType,
|
||||
RWBytes: rwBytes,
|
||||
ConsumedBytes: consumed,
|
||||
TotalBytes: total,
|
||||
}
|
||||
if len(err) > 0 {
|
||||
event.Err = err[0]
|
||||
}
|
||||
return event
|
||||
}
|
||||
|
||||
// 用户自定义Listener需要实现该方法
|
||||
type ProgressListener interface {
|
||||
ProgressChangedCallback(event *ProgressEvent)
|
||||
}
|
||||
|
||||
func progressCallback(listener ProgressListener, event *ProgressEvent) {
|
||||
if listener != nil && event != nil {
|
||||
listener.ProgressChangedCallback(event)
|
||||
}
|
||||
}
|
||||
|
||||
type teeReader struct {
|
||||
reader io.Reader
|
||||
writer io.Writer
|
||||
consumedBytes int64
|
||||
totalBytes int64
|
||||
listener ProgressListener
|
||||
}
|
||||
|
||||
func (r *teeReader) Read(p []byte) (int, error) {
|
||||
if r.consumedBytes == 0 {
|
||||
event := newProgressEvent(ProgressStartedEvent, 0, r.consumedBytes, r.totalBytes)
|
||||
progressCallback(r.listener, event)
|
||||
}
|
||||
|
||||
n, err := r.reader.Read(p)
|
||||
if err != nil && err != io.EOF {
|
||||
event := newProgressEvent(ProgressFailedEvent, 0, r.consumedBytes, r.totalBytes, err)
|
||||
progressCallback(r.listener, event)
|
||||
}
|
||||
if n > 0 {
|
||||
r.consumedBytes += int64(n)
|
||||
if r.writer != nil {
|
||||
if n, err := r.writer.Write(p[:n]); err != nil {
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
if r.listener != nil {
|
||||
event := newProgressEvent(ProgressDataEvent, int64(n), r.consumedBytes, r.totalBytes)
|
||||
progressCallback(r.listener, event)
|
||||
}
|
||||
}
|
||||
|
||||
if err == io.EOF {
|
||||
event := newProgressEvent(ProgressCompletedEvent, int64(n), r.consumedBytes, r.totalBytes)
|
||||
progressCallback(r.listener, event)
|
||||
}
|
||||
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (r *teeReader) Close() error {
|
||||
if rc, ok := r.reader.(io.ReadCloser); ok {
|
||||
return rc.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *teeReader) Size() int64 {
|
||||
return r.totalBytes
|
||||
}
|
||||
|
||||
func TeeReader(reader io.Reader, writer io.Writer, total int64, listener ProgressListener) *teeReader {
|
||||
return &teeReader{
|
||||
reader: reader,
|
||||
writer: writer,
|
||||
consumedBytes: 0,
|
||||
totalBytes: total,
|
||||
listener: listener,
|
||||
}
|
||||
}
|
||||
|
||||
type FixedLengthReader interface {
|
||||
io.Reader
|
||||
Size() int64
|
||||
}
|
||||
|
||||
type DefaultProgressListener struct {
|
||||
}
|
||||
|
||||
func (l *DefaultProgressListener) ProgressChangedCallback(event *ProgressEvent) {
|
||||
switch event.EventType {
|
||||
case ProgressStartedEvent:
|
||||
fmt.Printf("Transfer Start [ConsumedBytes/TotalBytes: %d/%d]\n",
|
||||
event.ConsumedBytes, event.TotalBytes)
|
||||
case ProgressDataEvent:
|
||||
fmt.Printf("\rTransfer Data [ConsumedBytes/TotalBytes: %d/%d, %d%%]",
|
||||
event.ConsumedBytes, event.TotalBytes, event.ConsumedBytes*100/event.TotalBytes)
|
||||
case ProgressCompletedEvent:
|
||||
fmt.Printf("\nTransfer Complete [ConsumedBytes/TotalBytes: %d/%d]\n",
|
||||
event.ConsumedBytes, event.TotalBytes)
|
||||
case ProgressFailedEvent:
|
||||
fmt.Printf("\nTransfer Failed [ConsumedBytes/TotalBytes: %d/%d] [Err: %v]\n",
|
||||
event.ConsumedBytes, event.TotalBytes, event.Err)
|
||||
default:
|
||||
fmt.Printf("Progress Changed Error: unknown progress event type\n")
|
||||
}
|
||||
}
|
||||
@@ -48,13 +48,13 @@ func TestServiceService_Get(t *testing.T) {
|
||||
},
|
||||
Buckets: []Bucket{
|
||||
{
|
||||
Name: "huadong-1253846586",
|
||||
Region: "ap-shanghai",
|
||||
Name: "huadong-1253846586",
|
||||
Region: "ap-shanghai",
|
||||
CreationDate: "2017-06-16T13:08:28Z",
|
||||
},
|
||||
{
|
||||
Name: "huanan-1253846586",
|
||||
Region: "ap-guangzhou",
|
||||
Name: "huanan-1253846586",
|
||||
Region: "ap-guangzhou",
|
||||
CreationDate: "2017-06-10T09:00:07Z",
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user