addInternalHandler registers a control subject handler.
(nc *nats.Conn, verb Verb, kind, id, name string, handler HandlerFunc)
| 667 | |
| 668 | // addInternalHandler registers a control subject handler. |
| 669 | func (s *service) addInternalHandler(nc *nats.Conn, verb Verb, kind, id, name string, handler HandlerFunc) error { |
| 670 | subj, err := ControlSubject(verb, kind, id) |
| 671 | if err != nil { |
| 672 | if stopErr := s.Stop(); stopErr != nil { |
| 673 | return errors.Join(err, fmt.Errorf("stopping service: %w", stopErr)) |
| 674 | } |
| 675 | return err |
| 676 | } |
| 677 | |
| 678 | s.verbSubs[name], err = nc.Subscribe(subj, func(msg *nats.Msg) { |
| 679 | handler(&request{msg: msg}) |
| 680 | }) |
| 681 | if err != nil { |
| 682 | if stopErr := s.Stop(); stopErr != nil { |
| 683 | return errors.Join(err, fmt.Errorf("stopping service: %w", stopErr)) |
| 684 | } |
| 685 | return err |
| 686 | } |
| 687 | return nil |
| 688 | } |
| 689 | |
| 690 | // reqHandler invokes the service request handler and modifies service stats |
| 691 | func (s *service) reqHandler(endpoint *Endpoint, req *request) { |
no test coverage detected