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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package models
  2. /// TODO 将分散在各处的公共结构体定义集中到这里来
  3. const (
  4. RedundancyRep = "rep"
  5. RedundancyEC = "ec"
  6. )
  7. // 冗余模式的描述信息
  8. type RedundancyConfigTypes interface{}
  9. type RedundancyConfigTypesConst interface {
  10. RepRedundancyConfig | ECRedundancyConfig
  11. }
  12. type RepRedundancyConfig struct {
  13. RepCount int `json:"repCount"`
  14. }
  15. func NewRepRedundancyConfig(repCount int) RepRedundancyConfig {
  16. return RepRedundancyConfig{
  17. RepCount: repCount,
  18. }
  19. }
  20. type ECRedundancyConfig struct {
  21. }
  22. // 冗余模式的具体配置
  23. type RedundancyDataTypes interface{}
  24. type RedundancyDataTypesConst interface {
  25. RepRedundancyData | ECRedundancyData
  26. }
  27. type RepRedundancyData struct {
  28. FileHash string `json:"fileHash"`
  29. }
  30. func NewRedundancyRepData(fileHash string) RepRedundancyData {
  31. return RepRedundancyData{
  32. FileHash: fileHash,
  33. }
  34. }
  35. type ECRedundancyData struct {
  36. Blocks []ObjectBlock `json:"blocks"`
  37. }
  38. func NewECRedundancyData(blocks []ObjectBlock) ECRedundancyData {
  39. return ECRedundancyData{
  40. Blocks: blocks,
  41. }
  42. }
  43. type ObjectBlock struct {
  44. Index int `json:"index"`
  45. FileHash string `json:"fileHash"`
  46. }
  47. func NewObjectBlock(index int, fileHash string) ObjectBlock {
  48. return ObjectBlock{
  49. Index: index,
  50. FileHash: fileHash,
  51. }
  52. }

公共库