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.

models.go 2.7 kB

1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package cdssdk
  2. import (
  3. "database/sql/driver"
  4. "fmt"
  5. "gitlink.org.cn/cloudream/common/pkgs/types"
  6. "gitlink.org.cn/cloudream/common/utils/serder"
  7. )
  8. const (
  9. ObjectPathSeperator = "/"
  10. )
  11. type NodeID int64
  12. type PackageID int64
  13. type ObjectID int64
  14. type UserID int64
  15. type BucketID int64
  16. type StorageID int64
  17. type LocationID int64
  18. /// TODO 将分散在各处的公共结构体定义集中到这里来
  19. type Redundancy interface {
  20. driver.Valuer
  21. }
  22. var RedundancyUnion = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[Redundancy](
  23. (*RepRedundancy)(nil),
  24. (*ECRedundancy)(nil),
  25. )), "type")
  26. type RepRedundancy struct {
  27. serder.Metadata `union:"rep"`
  28. Type string `json:"type"`
  29. }
  30. func NewRepRedundancy() *RepRedundancy {
  31. return &RepRedundancy{
  32. Type: "rep",
  33. }
  34. }
  35. func (b *RepRedundancy) Value() (driver.Value, error) {
  36. return serder.ObjectToJSONEx[Redundancy](b)
  37. }
  38. type ECRedundancy struct {
  39. serder.Metadata `union:"ec"`
  40. Type string `json:"type"`
  41. K int `json:"k"`
  42. N int `json:"n"`
  43. ChunkSize int `json:"chunkSize"`
  44. }
  45. func NewECRedundancy(k int, n int, chunkSize int) *ECRedundancy {
  46. return &ECRedundancy{
  47. Type: "ec",
  48. K: k,
  49. N: n,
  50. ChunkSize: chunkSize,
  51. }
  52. }
  53. func (b *ECRedundancy) Value() (driver.Value, error) {
  54. return serder.ObjectToJSONEx[Redundancy](b)
  55. }
  56. const (
  57. PackageStateNormal = "Normal"
  58. PackageStateDeleted = "Deleted"
  59. )
  60. type Package struct {
  61. PackageID PackageID `db:"PackageID" json:"packageID"`
  62. Name string `db:"Name" json:"name"`
  63. BucketID BucketID `db:"BucketID" json:"bucketID"`
  64. State string `db:"State" json:"state"`
  65. }
  66. type Object struct {
  67. ObjectID ObjectID `db:"ObjectID" json:"objectID"`
  68. PackageID PackageID `db:"PackageID" json:"packageID"`
  69. Path string `db:"Path" json:"path"`
  70. Size int64 `db:"Size" json:"size,string"`
  71. FileHash string `db:"FileHash" json:"fileHash"`
  72. Redundancy Redundancy `db:"Redundancy" json:"redundancy"`
  73. }
  74. type NodePackageCachingInfo struct {
  75. NodeID NodeID `json:"nodeID"`
  76. FileSize int64 `json:"fileSize"`
  77. ObjectCount int64 `json:"objectCount"`
  78. }
  79. type PackageCachingInfo struct {
  80. NodeInfos []NodePackageCachingInfo `json:"nodeInfos"`
  81. PackageSize int64 `json:"packageSize"`
  82. }
  83. func NewPackageCachingInfo(nodeInfos []NodePackageCachingInfo, packageSize int64) PackageCachingInfo {
  84. return PackageCachingInfo{
  85. NodeInfos: nodeInfos,
  86. PackageSize: packageSize,
  87. }
  88. }
  89. type CodeError struct {
  90. Code string `json:"code"`
  91. Message string `json:"message"`
  92. }
  93. func (e *CodeError) Error() string {
  94. return fmt.Sprintf("code: %s, message: %s", e.Code, e.Message)
  95. }