Documentation
¶
Overview ¶
Package commerce (pkg/commerce) is the embedded Commerce server. One backend, one HTTP handler. Mirrors pkg/tasks/embed.go shape:
cfg := commerce.EmbedConfig{DataDir: "/var/lib/commerce", HTTPAddr: ":8090"}
srv, err := commerce.Embed(ctx, cfg)
defer srv.Stop(ctx)
The legacy App in commerce.go is the bootstrap — server.go wires it into commerced/main.go cleanly. The /v1/commerce/* surface stays behind hanzoai/gateway and is gated by COMMERCED_REQUIRE_IDENTITY.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EmbedConfig ¶
type EmbedConfig struct {
DataDir string // "" → COMMERCE_DIR or ./commerce_data
HTTPAddr string // "" → COMMERCE_HTTP or 127.0.0.1:8090
Dev bool // dev mode — gin.DebugMode + reload-friendly logging
RequireIdentity bool // gateway trust: refuse requests without X-Org-Id/X-User-Id
Logger *slog.Logger // nil → slog.Default()
AllowedOrigins []string // CORS — usually ["*"] behind gateway
}
EmbedConfig configures the in-process Commerce server. Empty values fall through to commerce.DefaultConfig (env-based) so commerced binds the same env contract the legacy commerce binary did.
type Embedded ¶
type Embedded struct {
// contains filtered or unexported fields
}
Embedded is the handle to a running in-process Commerce server. The underlying *commerceApp.App owns the heavy lifting (DB, infra, KMS, hooks, cron) — Embedded wraps it for clean Stop/HTTPHandler/HTTPAddr access from commerced.
func Embed ¶
func Embed(ctx context.Context, cfg EmbedConfig) (*Embedded, error)
Embed bootstraps the Commerce app and returns a handle. Call Stop before the process exits.
func (*Embedded) App ¶
func (e *Embedded) App() *commerceApp.App
App exposes the underlying App for tests and hook registration.
func (*Embedded) HTTPHandler ¶
HTTPHandler returns the gin router as a plain http.Handler. commerced wraps this with healthz + the embedded SPA at /_/commerce/.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the per-request, org-scoped data layer. Each request lands on its own *db.DB shard keyed by the gateway-supplied X-Org-Id, so two orgs can never see each other's rows even if a handler bug forgets to scope its query.
func NewStore ¶
NewStore wraps a db.Manager. The returned Store has no org binding — call WithOrg to land on a specific shard.
func (*Store) DB ¶
DB returns the per-org *db.DB shard. It opens the shard lazily; the underlying db.Manager memoizes them so two requests on the same org share the same SQLite handle (with its own connection pool).
func (*Store) FromContext ¶
FromContext returns a Store bound to the org id attached by pkg/auth.Gin (or pkg/auth.RequireIdentity). Empty org → unscoped "system" shard, which is the legacy default for unauthenticated dev requests. A request that asks for tenant data without an org must have failed the gateway-trust gate already.