users

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package users is the canonical "owns its data, exposes typed REST" module: a minimal user catalog tagged DeployAs("users-svc") so it can be peeled out into its own binary later.

The Module declaration here is what `nexus gen clients` reads to emit zz_users_client_gen.go alongside this file. Other modules (e.g. checkout) consume `users.UsersClient` instead of touching the in-memory store directly — the codegen makes the local-vs- remote choice transparent at construction time.

Index

Constants

This section is empty.

Variables

View Source
var Module = nexus.Module("users",
	nexus.DeployAs("users-svc"),
	nexus.Provide(NewService),
	nexus.AsRest("GET", "/users/:id", NewGet),
	nexus.AsRest("GET", "/users", NewList),
)

Module is the wired declaration. DeployAs("users-svc") is the hint that drives codegen — without it, this module is "always local" and no client stub is emitted.

Functions

This section is empty.

Types

type GetArgs

type GetArgs struct {
	ID string `json:"id" uri:"id"`
}

GetArgs binds a path parameter named `id`. The framework's gin binding reads the `uri:"id"` tag; the generated client's path expansion reads the same tag — guaranteed to round-trip.

type ListArgs

type ListArgs struct{}

ListArgs is empty — kept as a real type (rather than struct{}) so the generated client method has a stable shape if filters are added.

type Service

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

Service holds the in-memory store. Real implementations would back it with a DB; this stays simple to keep the example focused on the codegen + cross-module wiring.

func NewService

func NewService(app *nexus.App) *Service

type User

type User struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

User is the public shape returned over the wire. Generated client code lives in this package, so it sees this type without an import and consumers in other packages get it via `users.User`.

func NewGet

func NewGet(svc *Service, p nexus.Params[GetArgs]) (*User, error)

NewGet returns a typed user by id. 404 surfaces as a *RemoteError on the client side (see the generated stub).

func NewList

func NewList(svc *Service, p nexus.Params[ListArgs]) ([]*User, error)

NewList streams every user. In a real service this would paginate; for the demo, just return the full slice.

type UsersClient

type UsersClient interface {
	Get(ctx context.Context, args GetArgs) (*User, error)
	List(ctx context.Context, args ListArgs) ([]*User, error)
}

UsersClient is the typed client surface for the "users" module. One method per AsRest handler in that module's declaration. The implementation is selected at construction time based on the running binary's deployment.

func NewUsersClient

func NewUsersClient(app *nexus.App) UsersClient

NewUsersClient returns the appropriate implementation for the running binary:

  • In-process LocalInvoker when this binary owns the "users-svc" deployment, OR when no deployment is set (monolith mode).
  • HTTP RemoteCaller reading USERS_SVC_URL otherwise.

Jump to

Keyboard shortcuts

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