Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander committed Mar 15, 2024
1 parent e280ba5 commit f9f45da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion roomserver/external/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewRoomserverAPIClient(intapi api.RoomserverInternalAPI, nats *jetstream.NA
return c
}

func (c *RoomserverAPIClient) PPerformBackfill(
func (c *RoomserverAPIClient) PerformBackfill(
ctx context.Context,
req *api.PerformBackfillRequest,
res *api.PerformBackfillResponse,
Expand Down
7 changes: 4 additions & 3 deletions setup/jetstream/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func setupNATS(process *process.ProcessContext, cfg *config.JetStream, nc *natsc
return s, nc
}

func CallAPI[req, res any](s *NATSInstance, component, endpoint string, rq req, rs res) error {
func CallAPI[req, res any](s *NATSInstance, component, endpoint string, rq *req, rs *res) error {
subj := fmt.Sprintf("API.%s.%s", component, endpoint)
j, err := json.Marshal(rq)
if err != nil {
Expand All @@ -252,15 +252,16 @@ func CallAPI[req, res any](s *NATSInstance, component, endpoint string, rq req,
return json.Unmarshal(resp.Data, rs)
}

func ListenAPI[req, res any](s *NATSInstance, component, endpoint string, fn func(req req, res res) error) error {
func ListenAPI[req, res any](s *NATSInstance, component, endpoint string, fn func(*req, *res) error) error {
subj := fmt.Sprintf("API.%s.%s", component, endpoint)
logrus.Infof("Listening on %s", subj)
_, err := s.Conn.Subscribe(subj, func(msg *natsclient.Msg) {
var req req
var res res
if err := json.Unmarshal(msg.Data, &req); err != nil {
return
}
if err := fn(req, res); err != nil {
if err := fn(&req, &res); err != nil {
return
}
j, err := json.Marshal(res)
Expand Down

0 comments on commit f9f45da

Please sign in to comment.