checkout

package
v0.23.4 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 3 Imported by: 0

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

View Source
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

func NewSubmit(svc *Service, p nexus.Params[SubmitArgs]) (*Receipt, error)

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

type Service struct {
	*nexus.Service
	// contains filtered or unexported fields
}

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.

func NewService

func NewService(app *nexus.App, u *users.Service) *Service

type SubmitArgs

type SubmitArgs struct {
	UserID  string `json:"userId"`
	OrderID string `json:"orderId"`
}

Jump to

Keyboard shortcuts

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