I originally had this function too, but I didn't find it very useful.
// ParseEventData parses the event data into the correct type.
func ParseEventData(e Event) (any, error) {
var data any
switch e.EventType {
case "incident.acknowledged", "incident.annotated", "incident.delegated",
"incident.escalated", "incident.priority_updated", "incident.reassigned",
"incident.reopened", "incident.triggered", "incident.unacknowledged":
data = &IncidentData{}
case "incident.conference_bridge.updated":
data = &IncidentConferenceBridgeData{}
case "incident.custom_field_values.updated":
data = &IncidentFieldValuesData{}
case "incident.responder.added", "incident.responder.replied":
data = &IncidentResponderData{}
case "incident.status_update_published":
data = &IncidentStatusUpdateData{}
case "incident.workflow.started", "incident.workflow.completed":
data = &IncidentWorkflowInstanceData{}
case "pagey.ping":
data = &PageyData{}
default:
return nil, fmt.Errorf("unrecognized event type: %q", e.EventType)
}
if err := json.Unmarshal(e.Data, data); err != nil {
return nil, err
}
return data, nil
}
I originally had this function too, but I didn't find it very useful.