greeter

package
v0.6.106 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package greeter is the service's domain component: it serves HelloService over every public protocol with one implementation and raises Greeted after every greeting.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSalute = errors.New("salute must not be empty")
	ErrSuffix = errors.New("suffix must be at most 8 characters on one line")
	// ErrStalled: the report loop has not ticked for three periods.
	ErrStalled = errors.New("greeter: report loop stalled")
)

Errors of Validate.

Functions

This section is empty.

Types

type Config

type Config struct {
	Salute string `json:"salute" schemapb:"default=Hello;description=Word before the name"`
	// Live: editable from the console, applied without restart.
	Suffix  config.Live[string] `json:"suffix"  schemapb:"default=!;description=Appended to every greeting"`
	Excited config.Live[bool]   `json:"excited" schemapb:"default=false"`
}

Config of the greeter.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks what the schema cannot: Open fails on it, and a live update it rejects (a suffix of nine characters) is not applied.

type Greeted

type Greeted struct {
	Name  string `json:"name"`
	Count uint64 `json:"count"`
	Text  string `json:"text,omitempty"`
}

Greeted is published after every greeting. Payloads evolve additively: Text was added after Name and Count, readers that predate it ignore it.

type Greeter

type Greeter struct {
	hellov1.UnimplementedHelloServiceServer
	deps.Component
	// contains filtered or unexported fields
}

Greeter is a component: a named node with its own logger, tracer and meter.

func New

func New(parent deps.Scope, cfg *Config, db deps.Dependency[*store.DB]) (*Greeter, error)

New creates the greeter under parent; everything it needs is passed in, the events it raises it declares itself.

func (*Greeter) Alive

func (g *Greeter) Alive(context.Context) error

Alive is the greeter's liveness check: the report loop, once started, keeps ticking.

func (*Greeter) Countdown

Countdown implements HelloService.

func (*Greeter) Greet

Greet implements HelloService.

func (*Greeter) Greeted

func (g *Greeter) Greeted() event.Ref[Greeted]

Greeted is the event the greeter raises.

func (*Greeter) Ready

func (g *Greeter) Ready(ctx context.Context) error

Ready is the greeter's readiness check: its templates build.

func (*Greeter) Record

func (g *Greeter) Record(ctx context.Context, name, text string)

Record records the greeting actually delivered, whether rendered locally or returned by a bound hook. The same metric and event path serves both. Publication failure (for example, running without NATS) is logged without failing the greeting, just like Text.

func (*Greeter) Register

func (g *Greeter) Register(r grpc.ServiceRegistrar)

Register is the one registration for native gRPC and ws-proto.

func (*Greeter) Text

func (g *Greeter) Text(ctx context.Context, name string) (string, error)

Text greets name and publishes Greeted; a publish that fails (no NATS) does not fail the greeting.

Jump to

Keyboard shortcuts

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