| @@ -1,7 +1,5 @@ | |||||
| package event | package event | ||||
| var _ = Register[*AgentCheckCache]() | |||||
| type AgentCheckCache struct { | type AgentCheckCache struct { | ||||
| EventBase | EventBase | ||||
| NodeID int64 `json:"nodeID"` | NodeID int64 `json:"nodeID"` | ||||
| @@ -14,3 +12,7 @@ func NewAgentCheckCache(nodeID int64, fileHashes []string) *AgentCheckCache { | |||||
| FileHashes: fileHashes, | FileHashes: fileHashes, | ||||
| } | } | ||||
| } | } | ||||
| func init() { | |||||
| Register[*AgentCheckCache]() | |||||
| } | |||||
| @@ -1,7 +1,5 @@ | |||||
| package event | package event | ||||
| var _ = Register[*AgentCheckState]() | |||||
| type AgentCheckState struct { | type AgentCheckState struct { | ||||
| EventBase | EventBase | ||||
| NodeID int64 `json:"nodeID"` | NodeID int64 `json:"nodeID"` | ||||
| @@ -12,3 +10,7 @@ func NewAgentCheckState(nodeID int64) *AgentCheckState { | |||||
| NodeID: nodeID, | NodeID: nodeID, | ||||
| } | } | ||||
| } | } | ||||
| func init() { | |||||
| Register[*AgentCheckState]() | |||||
| } | |||||
| @@ -1,7 +1,5 @@ | |||||
| package event | package event | ||||
| var _ = Register[*AgentCheckStorage]() | |||||
| type AgentCheckStorage struct { | type AgentCheckStorage struct { | ||||
| EventBase | EventBase | ||||
| StorageID int64 `json:"storageID"` | StorageID int64 `json:"storageID"` | ||||
| @@ -14,3 +12,7 @@ func NewAgentCheckStorage(storageID int64, packageIDs []int64) *AgentCheckStorag | |||||
| PackageIDs: packageIDs, | PackageIDs: packageIDs, | ||||
| } | } | ||||
| } | } | ||||
| func init() { | |||||
| Register[*AgentCheckStorage]() | |||||
| } | |||||
| @@ -1,7 +1,5 @@ | |||||
| package event | package event | ||||
| var _ = Register[*CheckCache]() | |||||
| type CheckCache struct { | type CheckCache struct { | ||||
| EventBase | EventBase | ||||
| NodeID int64 `json:"nodeID"` | NodeID int64 `json:"nodeID"` | ||||
| @@ -12,3 +10,7 @@ func NewCheckCache(nodeID int64) *CheckCache { | |||||
| NodeID: nodeID, | NodeID: nodeID, | ||||
| } | } | ||||
| } | } | ||||
| func init() { | |||||
| Register[*CheckCache]() | |||||
| } | |||||
| @@ -1,7 +1,5 @@ | |||||
| package event | package event | ||||
| var _ = Register[*CheckPackage]() | |||||
| type CheckPackage struct { | type CheckPackage struct { | ||||
| EventBase | EventBase | ||||
| PackageIDs []int64 `json:"packageIDs"` | PackageIDs []int64 `json:"packageIDs"` | ||||
| @@ -12,3 +10,7 @@ func NewCheckPackage(packageIDs []int64) *CheckPackage { | |||||
| PackageIDs: packageIDs, | PackageIDs: packageIDs, | ||||
| } | } | ||||
| } | } | ||||
| func init() { | |||||
| Register[*CheckPackage]() | |||||
| } | |||||
| @@ -1,7 +1,5 @@ | |||||
| package event | package event | ||||
| var _ = Register[*CheckRepCount]() | |||||
| type CheckRepCount struct { | type CheckRepCount struct { | ||||
| EventBase | EventBase | ||||
| FileHashes []string `json:"fileHashes"` | FileHashes []string `json:"fileHashes"` | ||||
| @@ -12,3 +10,7 @@ func NewCheckRepCount(fileHashes []string) *CheckRepCount { | |||||
| FileHashes: fileHashes, | FileHashes: fileHashes, | ||||
| } | } | ||||
| } | } | ||||
| func init() { | |||||
| Register[*CheckRepCount]() | |||||
| } | |||||
| @@ -1,28 +1,23 @@ | |||||
| package event | package event | ||||
| import ( | import ( | ||||
| "gitlink.org.cn/cloudream/common/pkgs/mq" | |||||
| "gitlink.org.cn/cloudream/common/pkgs/types" | "gitlink.org.cn/cloudream/common/pkgs/types" | ||||
| myreflect "gitlink.org.cn/cloudream/common/utils/reflect" | myreflect "gitlink.org.cn/cloudream/common/utils/reflect" | ||||
| "gitlink.org.cn/cloudream/common/utils/serder" | |||||
| ) | ) | ||||
| type Event interface { | type Event interface { | ||||
| Noop() | Noop() | ||||
| } | } | ||||
| var EventTypeUnino = types.NewTypeUnion[Event]() | |||||
| var EventTypeUnino = serder.UseTypeUnionExternallyTagged(types.Ref(types.NewTypeUnion[Event]())) | |||||
| type EventBase struct{} | type EventBase struct{} | ||||
| func (e *EventBase) Noop() {} | func (e *EventBase) Noop() {} | ||||
| // 注:此函数必须以var _ = Register[xxx]()的形式被调用,这样才能保证init中RegisterUnionType时 | |||||
| // TypeUnion不是空的。(因为包级变量初始化比init函数调用先进行) | |||||
| // 只能在init函数中调用,因为包级变量初始化比init函数调用先进行 | |||||
| func Register[T Event]() any { | func Register[T Event]() any { | ||||
| EventTypeUnino.Add(myreflect.TypeOf[T]()) | EventTypeUnino.Add(myreflect.TypeOf[T]()) | ||||
| return nil | return nil | ||||
| } | } | ||||
| func init() { | |||||
| mq.RegisterUnionType(EventTypeUnino) | |||||
| } | |||||