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.2 kB

1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 NodeID `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. Features []StorageFeature `json:"features" gorm:"column:Features; type:json; serializer:union"`
  16. }
  17. func (Storage) TableName() string {
  18. return "Storage"
  19. }
  20. func (s *Storage) String() string {
  21. return fmt.Sprintf("%v(%v)", s.Name, s.StorageID)
  22. }
  23. // 共享存储服务的配置数据
  24. type SharedStorage struct {
  25. StorageID StorageID `json:"storageID" gorm:"column:StorageID; primaryKey; type:bigint"`
  26. // 调度文件时保存文件的根路径
  27. LoadBase string `json:"loadBase" gorm:"column:LoadBase; type:varchar(1024); not null"`
  28. // 回源数据时数据存放位置的根路径
  29. DataReturnBase string `json:"dataReturnBase" gorm:"column:DataReturnBase; type:varchar(1024); not null"`
  30. }
  31. func (SharedStorage) TableName() string {
  32. return "SharedStorage"
  33. }
  34. // 存储服务地址
  35. type StorageAddress interface {
  36. GetType() string
  37. // 输出调试用的字符串,不要包含敏感信息
  38. String() string
  39. }
  40. var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[StorageAddress](
  41. (*LocalStorageAddress)(nil),
  42. )), "type")
  43. type LocalStorageAddress struct {
  44. serder.Metadata `union:"Local"`
  45. Type string `json:"type"`
  46. }
  47. func (a *LocalStorageAddress) GetType() string {
  48. return "Local"
  49. }
  50. func (a *LocalStorageAddress) String() string {
  51. return "Local"
  52. }
  53. type OSSAddress struct {
  54. serder.Metadata `union:"Local"`
  55. Region string `json:"region"`
  56. AK string `json:"accessKeyId"`
  57. SK string `json:"secretAccessKey"`
  58. Endpoint string `json:"endpoint"`
  59. Bucket string `json:"bucket"`
  60. }
  61. func (a *OSSAddress) GetType() string {
  62. return "OSSAddress"
  63. }
  64. func (a *OSSAddress) String() string {
  65. return "OSSAddress"
  66. }
  67. type OBSAddress struct {
  68. serder.Metadata `union:"Local"`
  69. Region string `json:"region"`
  70. AK string `json:"accessKeyId"`
  71. SK string `json:"secretAccessKey"`
  72. Endpoint string `json:"endpoint"`
  73. Bucket string `json:"bucket"`
  74. }
  75. func (a *OBSAddress) GetType() string {
  76. return "OBSAddress"
  77. }
  78. func (a *OBSAddress) String() string {
  79. return "OBSAddress"
  80. }
  81. type COSAddress struct {
  82. serder.Metadata `union:"Local"`
  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 *COSAddress) GetType() string {
  90. return "COSAddress"
  91. }
  92. func (a *COSAddress) String() string {
  93. return "COSAddress"
  94. }