package events
import "encoding/json"
type Envelope struct {
Type string `json:"type"`
Version int `json:"version"`
Payload json.RawMessage `json:"payload"`
}
Not every integration payload maps cleanly to a static struct. When I need to accept “mostly known” JSON but preserve unknown fields for auditing or forward compatibility, I use json.RawMessage. That allows me to decode the envelope (event name, version, timestamps) while storing the original payload bytes for later processing. The key is to validate what you depend on (like type and id) and treat everything else as opaque. In production, this is useful for webhook ingestion pipelines: you can store the raw payload, then parse it asynchronously with versioned logic, without breaking ingestion when the upstream adds fields. It also improves debuggability because you can reprocess historical events from storage. Just be careful to size-limit payloads and avoid logging raw bodies.
Related snips
package api
import (
"net/http"
"runtime/debug"
)
Expose build metadata for debugging deploys
export interface RetryOptions {
retries: number;
baseMs: number;
maxMs: number;
signal?: AbortSignal;
onRetry?: (attempt: number, delay: number, err: unknown) => void;
Exponential backoff with jitter for retries
package dbutil
import (
"context"
"github.com/jackc/pgconn"
Retry Postgres serialization failures with bounded attempts
package files
import (
"context"
"time"
Presigned S3 upload URLs (AWS SDK v2)
package deps
import (
"net"
"net/http"
"time"
HTTP client tuned for production: timeouts, transport, and connection reuse
package api
import (
"io"
"net/http"
"os"
Safe multipart uploads using temp files (bounded memory)
Share this code
Here's the card — post it anywhere.