users

package
v0.21.23 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 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.

Layout demonstrates multi-file shadow support:

types.go     — public types (User, *Args)
service.go   — Service struct, constructor, plain methods
handlers.go  — gin/graphql handler shims
module.go    — Module declaration

Each file contributes to the same `users` package; the shadow generator strips Service/handlers/Module-related declarations from each file and synthesizes one zz_shadow_gen.go containing the HTTP-stub Service. Public types in types.go are preserved verbatim in the shadow build (they're called by checkout's signatures).

Index

Constants

This section is empty.

Variables

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

Module is the wired declaration. The DeployAs tag is inferred from nexus.deploy.yaml — the manifest's `users-svc.owns: [users]` entry tells the framework this module belongs to the users-svc deployment unit. Add an explicit nexus.DeployAs("users-svc") here if you want the tag pinned in source (it overrides the manifest inference).

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 shadow generator'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 method has a stable shape if filters are added.

type SearchArgs added in v0.13.0

type SearchArgs struct {
	Prefix string `graphql:"prefix" json:"prefix"`
}

SearchArgs is the typed input for a GraphQL query.

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 build-time transport switch. In binaries that don't own users, the shadow generator replaces this struct with an HTTP-stub variant whose methods route over PeerCaller — same public method set, same type identifier, different body.

func NewService

func NewService(app *nexus.App) *Service

func (*Service) Get added in v0.14.0

func (s *Service) Get(ctx context.Context, args GetArgs) (*User, error)

Get returns a typed user by id.

func (*Service) List added in v0.14.0

func (s *Service) List(ctx context.Context, args ListArgs) ([]*User, error)

List streams every user.

func (*Service) Search added in v0.14.0

func (s *Service) Search(ctx context.Context, args SearchArgs) ([]*User, error)

Search returns users whose names begin with the supplied prefix.

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)

func NewList

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

func NewSearch added in v0.13.0

func NewSearch(svc *Service, p nexus.Params[SearchArgs]) ([]*User, error)

Jump to

Keyboard shortcuts

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