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 3.1 kB

1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. Type StorageType `json:"type" gorm:"column:Type; 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 StorageType interface {
  30. GetStorageType() string
  31. // 输出调试用的字符串,不要包含敏感信息
  32. String() string
  33. }
  34. var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[StorageType](
  35. (*LocalStorageType)(nil),
  36. (*OBSType)(nil),
  37. (*OSSType)(nil),
  38. (*COSType)(nil),
  39. )), "type")
  40. type LocalStorageType struct {
  41. serder.Metadata `union:"Local"`
  42. Type string `json:"type"`
  43. }
  44. func (a *LocalStorageType) GetStorageType() string {
  45. return "Local"
  46. }
  47. func (a *LocalStorageType) String() string {
  48. return "Local"
  49. }
  50. type OSSType struct {
  51. serder.Metadata `union:"OSS"`
  52. Type string `json:"type"`
  53. Region string `json:"region"`
  54. AK string `json:"accessKeyId"`
  55. SK string `json:"secretAccessKey"`
  56. Endpoint string `json:"endpoint"`
  57. Bucket string `json:"bucket"`
  58. }
  59. func (a *OSSType) GetStorageType() string {
  60. return "OSS"
  61. }
  62. func (a *OSSType) String() string {
  63. return "OSS"
  64. }
  65. type OBSType struct {
  66. serder.Metadata `union:"OBS"`
  67. Type string `json:"type"`
  68. Region string `json:"region"`
  69. AK string `json:"accessKeyId"`
  70. SK string `json:"secretAccessKey"`
  71. Endpoint string `json:"endpoint"`
  72. Bucket string `json:"bucket"`
  73. }
  74. func (a *OBSType) GetStorageType() string {
  75. return "OBS"
  76. }
  77. func (a *OBSType) String() string {
  78. return "OBS"
  79. }
  80. type COSType struct {
  81. serder.Metadata `union:"COS"`
  82. Type string `json:"type"`
  83. Region string `json:"region"`
  84. AK string `json:"accessKeyId"`
  85. SK string `json:"secretAccessKey"`
  86. Endpoint string `json:"endpoint"`
  87. Bucket string `json:"bucket"`
  88. }
  89. func (a *COSType) GetStorageType() string {
  90. return "COS"
  91. }
  92. func (a *COSType) String() string {
  93. return "COS"
  94. }