move more code

This commit is contained in:
matst80
2025-12-02 23:23:59 +01:00
parent 5f6a7c47c9
commit a0142c2698
12 changed files with 708 additions and 696 deletions

View File

@@ -95,14 +95,18 @@ type MutationHandler interface {
type RegisteredMutation[V any, T proto.Message] struct {
name string
handler func(*V, T) error
create func() T
create func() proto.Message
msgType reflect.Type
}
func NewMutation[V any, T proto.Message](handler func(*V, T) error, create func() T) *RegisteredMutation[V, T] {
func NewMutation[V any, T proto.Message](handler func(*V, T) error) *RegisteredMutation[V, T] {
// Derive the name and message type from a concrete instance produced by create().
// This avoids relying on reflect.TypeFor (which can yield unexpected results in some toolchains)
// and ensures we always peel off the pointer layer for proto messages.
create := func() proto.Message {
m := new(T)
return *m
}
instance := create()
rt := reflect.TypeOf(instance)
if rt.Kind() == reflect.Ptr {