Help us shape the future of Go! Take the 2026 Go Developer Survey

orders

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 15 Imported by: 0

README

Order integration reference

This package demonstrates business-transaction safety around Webhook Redrive. It is source to adapt inside your application, not another required service.

  • Create commits an order and immutable outbox bytes together.
  • NewPublisher and PublishOne submit pending rows with a stable idempotency key and persist acceptance.
  • Receiver verifies signatures, then commits a business receipt and order-total update together.
  • ReceiverWithKeys accepts old and new keys during a coordinated signing rotation. Follow the retirement procedure before removing the old key.

Use a dedicated schema for schema.sql. Credentials stay outside the outbox. The API principal must have ingest; endpoint registration is a separate administrative step.

Run the complete producer-to-receiver demo from the repository root with a local TEST_DATABASE_URL:

go test -race -count=1 -v ./internal/integration -run '^TestOutboxToReceiverDemo$'

The integration guide covers setup, blocked outbox rows, credential rotation, receipt retention, and the wire format. The demo asserts one business action after duplicate delivery; it does not promise exactly-once external side effects.

Documentation

Overview

Package orders is a reference integration, not a service dependency or SDK.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusinessConflict = errors.New("business event identity conflicts with processed body")
View Source
var ErrPublish = errors.New("outbox submission not acknowledged")
View Source
var Schema string

Schema belongs to the example application, never the delivery schema.

Functions

func Create

func Create(ctx context.Context, pool *pgxpool.Pool, event Created, endpointID string, now time.Time) error

Create commits the business change and immutable outgoing bytes together. Generate the two UUIDs once before calling; persist no credentials in outbox.

func Receiver

func Receiver(pool *pgxpool.Pool, secret []byte, now func() time.Time) http.Handler

Receiver verifies exact bytes before reading the authenticated business ID. Give each integration its own secret and receipt namespace. Never trust the unsigned X-Webhook-ID or X-Webhook-Event headers for business decisions.

func ReceiverWithKeys

func ReceiverWithKeys(pool *pgxpool.Pool, keys [][]byte, now func() time.Time) http.Handler

ReceiverWithKeys accepts old and new signing keys during a planned rotation. Rebuild the handler after retirement rather than mutating its key ring.

Types

type Created

type Created struct {
	EventID     string `json:"event_id"`
	Type        string `json:"type"`
	OrderID     string `json:"order_id"`
	AmountCents int64  `json:"amount_cents"`
}

type Publisher

type Publisher struct {
	// contains filtered or unexported fields
}

func NewPublisher

func NewPublisher(pool *pgxpool.Pool, api, token string) (*Publisher, error)

NewPublisher accepts a deployment-controlled API origin, never event input. Call PublishOne periodically. A five-second persisted delay bounds retries.

func (*Publisher) Close

func (p *Publisher) Close()

func (*Publisher) PublishOne

func (p *Publisher) PublishOne(ctx context.Context, now time.Time) (bool, error)

PublishOne sends one pending row without holding a transaction across HTTP. Concurrent publishers can submit the same row: API idempotency makes that safe. This deliberately favors a small reference over a second queue engine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL