MCPcopy Create free account
hub / github.com/GoogleChrome/webstatus.dev / HandleMessage

Method HandleMessage

lib/event/router.go:70–88  ·  view source on GitHub ↗

HandleMessage is the single entry point.

(ctx context.Context, eventID string, data []byte)

Source from the content-addressed store, hash-verified

68
69// HandleMessage is the single entry point.
70func (r *Router) HandleMessage(ctx context.Context, eventID string, data []byte) error {
71 // 1. Efficient Peek: We only parse the metadata fields.
72 // The rest of the JSON is captured as RawMessage without full decoding.
73 var env envelope
74 if err := json.Unmarshal(data, &env); err != nil {
75 return fmt.Errorf("%w: %w: %w", ErrUnprocessableEntity, ErrInvalidEnvelope, err)
76 }
77
78 // 2. Find matching route
79 for _, route := range r.routes {
80 if route.Matches(env.Kind, env.APIVersion) {
81 // 3. Dispatch using only the inner 'data' payload
82
83 return route.Dispatch(ctx, eventID, env.Data)
84 }
85 }
86
87 return fmt.Errorf("%w: %w: kind=%q version=%q", ErrUnprocessableEntity, ErrNoHandler, env.Kind, env.APIVersion)
88}
89
90// envelope is used for the initial peek.
91type envelope struct {

Callers 6

TestHandleMessageSuccessFunction · 0.95
TestHandleMessageErrorsFunction · 0.95
SubscribeMethod · 0.80
SubscribeMethod · 0.80
SubscribeMethod · 0.80
SubscribeMethod · 0.80

Calls 2

MatchesMethod · 0.65
DispatchMethod · 0.65

Tested by 2

TestHandleMessageSuccessFunction · 0.76
TestHandleMessageErrorsFunction · 0.76