项目作者: michalswi

项目描述 :
azure sdk for golang - use blob storage
高级语言: Go
项目地址: git://github.com/michalswi/azure_blob.git
创建时间: 2020-02-07T11:24:26Z
项目社区:https://github.com/michalswi/azure_blob

开源协议:

下载


Official Azure SDK source.

  1. go build
  2. export AZURE_STORAGE_ACCOUNT=
  3. export AZURE_STORAGE_KEY=
  4. export SA_CONTAINER_NAME=tfstate
  5. ./azure_blob -h
  6. # create container
  7. $ ./azure_blob --action createContainer
  8. 2022/05/26 19:13:50 Container tfstate created.
  9. [optional]$ az storage container list --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_KEY --output table
  10. # create files locally and upload to blobs (one file one blob)
  11. $ ./azure_blob --action createUploadFile
  12. 2022/05/26 19:16:55 Creating a dummy file: tweety-c30b
  13. 2022/05/26 19:16:55 File tweety-c30b created.
  14. 2022/05/26 19:16:55 Uploading the file with blob name: tweety-c30b
  15. $ ./azure_blob --action createUploadFile
  16. 2022/05/26 19:17:31 Creating a dummy file: tweety-8230
  17. 2022/05/26 19:17:31 File tweety-8230 created.
  18. 2022/05/26 19:17:31 Uploading the file with blob name: tweety-8230
  19. $ ./azure_blob --action createUploadFile
  20. 2022/05/26 19:17:34 Creating a dummy file: tweety-35f7
  21. 2022/05/26 19:17:34 File tweety-35f7 created.
  22. 2022/05/26 19:17:34 Uploading the file with blob name: tweety-35f7
  23. # list blobs
  24. # >> 'size' is expressed in bytes
  25. $ ./azure_blob --action list | jq
  26. {
  27. "data": [
  28. {
  29. "id": 1,
  30. "file_name": "tweety-35f7",
  31. "size": 20,
  32. "creation": "2022-05-26T17:17:35Z",
  33. "content_type": "application/octet-stream"
  34. },
  35. {
  36. "id": 2,
  37. "file_name": "tweety-8230",
  38. "size": 20,
  39. "creation": "2022-05-26T17:17:32Z",
  40. "content_type": "application/octet-stream"
  41. },
  42. {
  43. "id": 3,
  44. "file_name": "tweety-c30b",
  45. "size": 20,
  46. "creation": "2022-05-26T17:16:56Z",
  47. "content_type": "application/octet-stream"
  48. }
  49. ]
  50. }
  51. $ ./azure_blob --action list | jq '.data[].file_name'
  52. "tweety-35f7"
  53. "tweety-8230"
  54. "tweety-c30b"
  55. [optional]$ az storage blob list --container-name $SA_CONTAINER_NAME --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_KEY --output table
  56. # download data from blob
  57. $ ./azure_blob --action download tweety-35f7
  58. Blob tweety-b5c6 downloaded.
  59. $ cat /tmp/tweety-35f7
  60. Tweety vs Sylvester
  61. # delete container
  62. ./azure_blob --action deleteContainer
  63. 2022/05/26 19:32:12 Container tfstate deleted.
  64. [optional]
  65. az storage container list --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_KEY --output table
  66. # remove local files
  67. $ ./azure_blob --action removeLocal ./tweety-35f7
  68. 2022/05/26 13:35:11 File ./tweety-35f7 removed.