31
32
// NewCommandHandlerRegistry creates a new [CommandHandlerRegistry].
34
>
return &CommandHandlerRegistry{
35
>
handlers: make(map[enumspb.CommandType]CommandHandler),
36
>
}
37
>
}
38
39
// Register registers a [CommandHandler] for a given command type.
40
// Returns an [ErrDuplicateRegistration] if a handler for the given command is already registered.
41
// All registration is expected to happen in a single thread on process initialization.
42
>
func (r *CommandHandlerRegistry) Register(t enumspb.CommandType, handler CommandHandler) error {
command_handler.go
43
>
if existing, ok := r.handlers[t]; ok {
44
return fmt.Errorf("%w: command handler for %v: %v", ErrDuplicateRegistration, t, existing)
45
}
47
>
return nil
48
}
49