Open bounoable opened 1 month ago
Support command payload validation:
package auth type registerPayload struct { Name string Email string } func (payload registerPayload) Validate() error { if payload.Name == "" { return errors.New("empty name") } if !isValidEmail(payload.Email) { return fmt.Errorf("invalid email address: %s", payload.Email) } return nil } func RegisterUser(id uuid.UUID, name string, email string) command.Cmd[registerPayload] { return command.New("auth.user.register", registerPayload{name, email}, command.Aggregate("auth.user", id)) } func HandleCommands(ctx context.Context, bus command.Bus) <-chan error { return command.MustHandle(ctx, bus, "auth.user.register", func(ctx command.Context) error { // ... this will only execute if ctx.Payload() valid ... return nil }) }
Support command payload validation: