handler.go 620 B

1234567891011121314151617181920212223242526
  1. package main
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "time"
  7. "github.com/google/uuid"
  8. )
  9. // HandleDummy is blissfully unaware of SQS, and could therefore be used as a handler for another message queue.
  10. func HandleDummy(_ context.Context, enc *json.Encoder, msg []byte) error {
  11. type EventBody struct {
  12. EventID uuid.UUID `json:"event_id"`
  13. EventTime time.Time `json:"event_time"`
  14. Data map[string]int `json:"data,omitempty"`
  15. }
  16. evt := EventBody{}
  17. if err := json.Unmarshal(msg, &evt); err != nil {
  18. return fmt.Errorf("error parsing body as JSON: %w", err)
  19. }
  20. enc.Encode(evt)
  21. return nil
  22. }