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.

object.go 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package models
  2. import (
  3. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  4. stgmod "gitlink.org.cn/cloudream/storage/common/models"
  5. "gorm.io/gorm"
  6. "time"
  7. )
  8. type Object struct {
  9. ObjectID cdssdk.ObjectID `gorm:"column:ObjectID; primaryKey; type:bigint; autoIncrement" json:"objectID"`
  10. PackageID cdssdk.PackageID `gorm:"column:PackageID; type:bigint; not null" json:"packageID"`
  11. Path string `gorm:"column:Path; type:varchar(1024); not null" json:"path"`
  12. Size int64 `gorm:"column:Size; type:bigint; not null" json:"size"`
  13. FileHash string `gorm:"column:FileHash; type:varchar(255); not null" json:"fileHash"`
  14. Status Status `gorm:"column:Status; type:tinyint; not null" json:"status"`
  15. FaultTolerance float64 `gorm:"column:faultTolerance; type:float; not null" json:"faultTolerance"`
  16. Redundancy float64 `gorm:"column:redundancy; type:float; not null" json:"redundancy"`
  17. AvgAccessCost float64 `gorm:"column:avgAccessCost; type:float; not null" json:"avgAccessCost"`
  18. Timestamp time.Time `gorm:"column:Timestamp; type:datatime; not null" json:"timestamp"`
  19. }
  20. func (Object) TableName() string {
  21. return "object"
  22. }
  23. // ObjectRepository 块传输记录的 Repository
  24. type ObjectRepository struct {
  25. repo *GormRepository
  26. }
  27. // NewObjectRepository 创建 ObjectRepository 实例
  28. func NewObjectRepository(db *gorm.DB) *ObjectRepository {
  29. return &ObjectRepository{repo: NewGormRepository(db)}
  30. }
  31. // CreateObject 创建块传输记录
  32. func (r *ObjectRepository) CreateObject(object *Object) error {
  33. return r.repo.Create(object)
  34. }
  35. // GetObjectByID 查询单个Object
  36. func (r *ObjectRepository) GetObjectByID(objectID int64) (*Object, error) {
  37. var object Object
  38. query := "SELECT * FROM object WHERE ObjectID = ?"
  39. err := r.repo.db.Raw(query, objectID).First(&object).Error
  40. if err != nil {
  41. return nil, err
  42. }
  43. return &object, nil
  44. }
  45. // UpdateObject 更新块传输记录
  46. func (r *ObjectRepository) UpdateObject(object *Object) error {
  47. return r.repo.Update(object)
  48. }
  49. // GetAllObjects 获取所有块传输记录
  50. func (r *ObjectRepository) GetAllObjects() ([]Object, error) {
  51. var objects []Object
  52. err := r.repo.GetAll(&objects)
  53. if err != nil {
  54. return nil, err
  55. }
  56. return objects, nil
  57. }
  58. // ProcessObject 处理 Object 数据
  59. func ProcessObject(data stgmod.ObjectChange) {
  60. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。