You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

bucket.go 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package cmdline
  2. import (
  3. "fmt"
  4. "github.com/jedib0t/go-pretty/v6/table"
  5. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  6. )
  7. func BucketListUserBuckets(ctx CommandContext) error {
  8. userID := cdssdk.UserID(1)
  9. buckets, err := ctx.Cmdline.Svc.BucketSvc().GetUserBuckets(userID)
  10. if err != nil {
  11. return err
  12. }
  13. fmt.Printf("Find %d buckets for user %d:\n", len(buckets), userID)
  14. tb := table.NewWriter()
  15. tb.AppendHeader(table.Row{"ID", "Name", "CreatorID"})
  16. for _, bucket := range buckets {
  17. tb.AppendRow(table.Row{bucket.BucketID, bucket.Name, bucket.CreatorID})
  18. }
  19. fmt.Print(tb.Render())
  20. return nil
  21. }
  22. func BucketCreateBucket(ctx CommandContext, bucketName string) error {
  23. userID := cdssdk.UserID(1)
  24. bucketID, err := ctx.Cmdline.Svc.BucketSvc().CreateBucket(userID, bucketName)
  25. if err != nil {
  26. return err
  27. }
  28. fmt.Printf("Create bucket %v success, id: %v", bucketName, bucketID)
  29. return nil
  30. }
  31. func BucketDeleteBucket(ctx CommandContext, bucketID cdssdk.BucketID) error {
  32. userID := cdssdk.UserID(1)
  33. err := ctx.Cmdline.Svc.BucketSvc().DeleteBucket(userID, bucketID)
  34. if err != nil {
  35. return err
  36. }
  37. fmt.Printf("Delete bucket %d success ", bucketID)
  38. return nil
  39. }
  40. func init() {
  41. commands.MustAdd(BucketListUserBuckets, "bucket", "ls")
  42. commands.MustAdd(BucketCreateBucket, "bucket", "new")
  43. commands.MustAdd(BucketDeleteBucket, "bucket", "delete")
  44. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。