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.

hubinfo.go 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package models
  2. import (
  3. "encoding/json"
  4. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  5. stgmod "gitlink.org.cn/cloudream/storage/common/models"
  6. "gorm.io/datatypes"
  7. )
  8. // LocalHub 本地结构体,嵌入cdssdk.Hub
  9. type LocalHub struct {
  10. cdssdk.Hub
  11. }
  12. type ConcreteHubType struct {
  13. Address string
  14. }
  15. func (c ConcreteHubType) GetStorageType() string {
  16. return c.Address
  17. }
  18. func (c ConcreteHubType) String() string {
  19. return c.Address
  20. }
  21. func (s *LocalHub) UnmarshalJSON(data []byte) error {
  22. // 定义一个临时结构体来解析 JSON
  23. type Alias LocalHub
  24. aux := &struct {
  25. Address string `json:"address"`
  26. *Alias
  27. }{
  28. Alias: (*Alias)(s),
  29. }
  30. if err := json.Unmarshal(data, &aux); err != nil {
  31. return err
  32. }
  33. s.Address = ConcreteHubType{Address: aux.Address}
  34. return nil
  35. }
  36. func ProcessHubInfo(data stgmod.HubInfo) {
  37. repo := NewHubRepository(DB)
  38. jsonData, _ := json.Marshal(data.Body.HubInfo.Address)
  39. HubInfo := &Hub{
  40. HubID: cdssdk.HubID(data.Body.HubID),
  41. Name: data.Body.HubInfo.Name,
  42. Address: datatypes.JSON(jsonData),
  43. }
  44. //先判断传输数据的类型
  45. switch data.Body.Type {
  46. case "add":
  47. err := repo.CreateHub(HubInfo)
  48. if err != nil {
  49. return
  50. }
  51. case "update":
  52. err := repo.UpdateHub(HubInfo)
  53. if err != nil {
  54. return
  55. }
  56. case "delete":
  57. err := repo.DeleteHub(HubInfo)
  58. if err != nil {
  59. return
  60. }
  61. default:
  62. return
  63. }
  64. }

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