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.

event.go 1.2 kB

2 years ago
2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package event
  2. import (
  3. "fmt"
  4. "reflect"
  5. "gitlink.org.cn/cloudream/common/pkgs/distlock"
  6. event "gitlink.org.cn/cloudream/common/pkgs/event"
  7. "gitlink.org.cn/cloudream/common/pkgs/typedispatcher"
  8. mydb "gitlink.org.cn/cloudream/storage/common/pkgs/db"
  9. scevt "gitlink.org.cn/cloudream/storage/common/pkgs/mq/scanner/event"
  10. )
  11. type ExecuteArgs struct {
  12. DB *mydb.DB
  13. DistLock *distlock.Service
  14. }
  15. type Executor = event.Executor[ExecuteArgs]
  16. type ExecuteContext = event.ExecuteContext[ExecuteArgs]
  17. type Event = event.Event[ExecuteArgs]
  18. type ExecuteOption = event.ExecuteOption
  19. func NewExecutor(db *mydb.DB, distLock *distlock.Service) Executor {
  20. return event.NewExecutor(ExecuteArgs{
  21. DB: db,
  22. DistLock: distLock,
  23. })
  24. }
  25. var msgDispatcher = typedispatcher.NewTypeDispatcher[Event]()
  26. func FromMessage(msg scevt.Event) (Event, error) {
  27. event, ok := msgDispatcher.Dispatch(msg)
  28. if !ok {
  29. return nil, fmt.Errorf("unknow event message type: %s", reflect.TypeOf(msg).String())
  30. }
  31. return event, nil
  32. }
  33. func RegisterMessageConvertor[T any, TEvt Event](converter func(msg T) TEvt) {
  34. typedispatcher.Add(msgDispatcher, func(msg T) Event {
  35. return converter(msg)
  36. })
  37. }

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