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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. "gitlink.org.cn/cloudream/storage/common/pkgs/sysevent"
  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. // 实现 Watcher 接口的结构体
  37. type HubInfoWatcher struct {
  38. Name string
  39. }
  40. // 实现 OnEvent 方法
  41. func (w *HubInfoWatcher) OnEvent(event sysevent.SysEvent) {
  42. repo := NewHubRepository(DB)
  43. switch body := event.Body.(type) {
  44. case *stgmod.BodyNewHub:
  45. err := repo.CreateHub(&Hub{
  46. HubID: body.Info.HubID,
  47. Name: body.Info.Name,
  48. Address: body.Info.Address,
  49. })
  50. if err != nil {
  51. return
  52. }
  53. case *stgmod.BodyHubUpdated:
  54. err := repo.UpdateHub(&Hub{
  55. HubID: body.Info.HubID,
  56. Name: body.Info.Name,
  57. Address: body.Info.Address,
  58. })
  59. if err != nil {
  60. return
  61. }
  62. case *stgmod.BodyHubDeleted:
  63. err := repo.DeleteHub(&Hub{
  64. HubID: body.HubID,
  65. })
  66. if err != nil {
  67. return
  68. }
  69. }
  70. }

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