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.

storage.go 2.9 kB

1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package cdssdk
  2. import (
  3. "fmt"
  4. "gitlink.org.cn/cloudream/common/pkgs/types"
  5. "gitlink.org.cn/cloudream/common/utils/serder"
  6. )
  7. type Storage struct {
  8. StorageID StorageID `json:"storageID" gorm:"column:StorageID; primaryKey; type:bigint; autoIncrement;"`
  9. Name string `json:"name" gorm:"column:Name; type:varchar(256); not null"`
  10. // 完全管理此存储服务的Hub的ID
  11. MasterHub HubID `json:"masterHub" gorm:"column:MasterHub; type:bigint; not null"`
  12. // 存储服务的地址,包含鉴权所需数据
  13. Address StorageAddress `json:"address" gorm:"column:Address; type:json; not null; serializer:union"`
  14. // 分片存储服务的配置数据
  15. ShardStore ShardStoreConfig `json:"shardStore" gorm:"column:ShardStore; type:json; serializer:union"`
  16. // 共享存储服务的配置数据
  17. SharedStore SharedStoreConfig `json:"sharedStore" gorm:"column:SharedStore; type:json; serializer:union"`
  18. // SharedStore
  19. // 存储服务拥有的特别功能
  20. Features []StorageFeature `json:"features" gorm:"column:Features; type:json; serializer:union"`
  21. }
  22. func (Storage) TableName() string {
  23. return "Storage"
  24. }
  25. func (s *Storage) String() string {
  26. return fmt.Sprintf("%v(%v)", s.Name, s.StorageID)
  27. }
  28. // 存储服务地址
  29. type StorageAddress interface {
  30. GetType() string
  31. // 输出调试用的字符串,不要包含敏感信息
  32. String() string
  33. }
  34. var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[StorageAddress](
  35. (*LocalStorageAddress)(nil),
  36. )), "type")
  37. type LocalStorageAddress struct {
  38. serder.Metadata `union:"Local"`
  39. Type string `json:"type"`
  40. }
  41. func (a *LocalStorageAddress) GetType() string {
  42. return "Local"
  43. }
  44. func (a *LocalStorageAddress) String() string {
  45. return "Local"
  46. }
  47. type OSSAddress struct {
  48. serder.Metadata `union:"Local"`
  49. Region string `json:"region"`
  50. AK string `json:"accessKeyId"`
  51. SK string `json:"secretAccessKey"`
  52. Endpoint string `json:"endpoint"`
  53. Bucket string `json:"bucket"`
  54. }
  55. func (a *OSSAddress) GetType() string {
  56. return "OSSAddress"
  57. }
  58. func (a *OSSAddress) String() string {
  59. return "OSSAddress"
  60. }
  61. type OBSAddress struct {
  62. serder.Metadata `union:"Local"`
  63. Region string `json:"region"`
  64. AK string `json:"accessKeyId"`
  65. SK string `json:"secretAccessKey"`
  66. Endpoint string `json:"endpoint"`
  67. Bucket string `json:"bucket"`
  68. }
  69. func (a *OBSAddress) GetType() string {
  70. return "OBSAddress"
  71. }
  72. func (a *OBSAddress) String() string {
  73. return "OBSAddress"
  74. }
  75. type COSAddress struct {
  76. serder.Metadata `union:"Local"`
  77. Region string `json:"region"`
  78. AK string `json:"accessKeyId"`
  79. SK string `json:"secretAccessKey"`
  80. Endpoint string `json:"endpoint"`
  81. Bucket string `json:"bucket"`
  82. }
  83. func (a *COSAddress) GetType() string {
  84. return "COSAddress"
  85. }
  86. func (a *COSAddress) String() string {
  87. return "COSAddress"
  88. }