Documentation
¶
Overview ¶
Package checkout demonstrates a module that *consumes* another module by importing its *Service directly. The same Go call — `svc.users.Get(ctx, users.GetArgs{ID: ...})` — works in monolith mode (direct method call) and in split mode (HTTP via the shadow generator's stub *users.Service), with no edits to this file when you peel users out into its own binary. The transport switch happens at compile time via `nexus build --deployment X`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Module = nexus.Module("checkout", nexus.DeployAs("checkout-svc"), nexus.Provide(NewService), nexus.AsRest("POST", "/checkout", NewSubmit), )
Module declares one POST endpoint. DeployAs makes checkout its own deployment unit so `nexus dev --split` boots it as a separate subprocess from users, exercising the real HTTP path between them via the codegen'd users.UsersClient.
Functions ¶
This section is empty.
Types ¶
type Receipt ¶
type Receipt struct {
OrderID string `json:"orderId"`
UserID string `json:"userId"`
Display string `json:"display"`
}
func NewSubmit ¶
NewSubmit fetches the user via the typed client (monolith: direct invoke; split: HTTP) and returns a receipt that includes the user's display name. The handler is unaware of which transport ran the users.Get call — this is the framework's contract.
In split mode with multiple users-svc replicas, WithRouteKey pins every checkout for the same user to the same users replica — useful when the users service maintains per-user in-memory caches or connection state. Affinity is best-effort: a healthy preferred replica is reused; an ejected one falls forward via the framework's linear probe (see nexus.WithRouteKey docs).
In monolith mode the route key is ignored — the users.Service call is in-process, no peer selection happens.
type Service ¶
Service is checkout's service wrapper. Its constructor takes a *users.Service — the build tool decides at compile time whether that's the real local struct (monolith / users-svc binaries) or an HTTP-stub redefinition emitted by the shadow generator (checkout-svc binary). The type identifier is identical in both.