MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / Dispatch

Method Dispatch

api/pkg/handlers/events_handler.go:46–78  ·  view source on GitHub ↗

Dispatch a cloud event This is an internal API so no documentation provided

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

44// Dispatch a cloud event
45// This is an internal API so no documentation provided
46func (h *EventsHandler) Dispatch(c fiber.Ctx) error {
47 ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger)
48 defer span.End()
49
50 var request cloudevents.Event
51 if err := c.Bind().Body(&request); err != nil {
52 msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request)
53 ctxLogger.Warn(stacktrace.Propagate(err, msg))
54 return h.responseBadRequest(c, err)
55 }
56
57 if err := request.Validate(); err != nil {
58 msg := fmt.Sprintf("validation errors [%s], while dispatching event [%+#v]", spew.Sdump(err.Error()), request)
59 ctxLogger.Warn(stacktrace.NewError(msg))
60 return h.responseUnprocessableEntity(c, map[string][]string{"event": {err.Error()}}, "validation errors while dispatching event")
61 }
62
63 if h.userIDFomContext(c) != h.queueConfig.UserID {
64 msg := fmt.Sprintf("user with ID [%s], cannot dispatch event [%+#v]", h.userIDFomContext(c), request)
65 ctxLogger.Error(stacktrace.NewError(msg))
66 return h.responseForbidden(c)
67 }
68
69 ctxLogger.Info(fmt.Sprintf("handling [%s] event with ID [%s]", request.Type(), request.ID()))
70 err := h.service.DispatchSync(ctx, request)
71 if err != nil {
72 msg := fmt.Sprintf("cannot dispatch [%s] event with ID [%s]", request.Type(), request.ID())
73 ctxLogger.Error(stacktrace.Propagate(err, msg))
74 return h.responseInternalServerError(c)
75 }
76
77 return h.responseNoContent(c, "event dispatched successfully")
78}

Callers

nothing calls this directly

Calls 11

responseBadRequestMethod · 0.80
userIDFomContextMethod · 0.80
responseForbiddenMethod · 0.80
DispatchSyncMethod · 0.80
responseNoContentMethod · 0.80
WarnMethod · 0.65
ErrorMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected