Documentation
¶
Overview ¶
Package resource defines the abstractions nexus uses to know about databases, caches, message queues, and other external dependencies so they show up in the dashboard's Architecture view with health status.
nexus does not ship concrete DB/cache implementations — users keep their own (GORM+failsafe, Redis/go-cache hybrid, etc.) and register them as Resources in one line:
app.Register(resource.NewDatabase("main", "Primary PG", nil, dbm.IsConnected, resource.AsDefault()))
app.Register(resource.NewCache("session", "Redis hybrid", nil, cache.IsRedisConnected, resource.AsDefault()))
Services then reference resources by name, not by instance:
app.Service("adverts").Using("").MountGraphQL(...) // default DB
app.Service("qb").Using("questions", "session").MountGraphQL(...) // explicit
app.Service("uaa").UsingDefaults().MountGraphQL(...) // default of every kind
Index ¶
- type Kind
- type Option
- type Resource
- func NewCache(name, desc string, details map[string]any, healthy func() bool, opts ...Option) Resource
- func NewDatabase(name, desc string, details map[string]any, healthy func() bool, opts ...Option) Resource
- func NewQueue(name, desc string, details map[string]any, healthy func() bool, opts ...Option) Resource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*simple)
Option tweaks a resource at construction time.
func AsDefault ¶
func AsDefault() Option
AsDefault marks a resource as the default for its Kind. When a Service calls .Using("") (database) or .UsingDefaults() (all kinds), nexus picks the one flagged AsDefault. If none is flagged, the lexically-first resource of the kind wins.
func WithDetails ¶
WithDetails replaces the static details map with a function called on every dashboard snapshot. Use for live-varying metadata — the canonical case is a cache reporting "redis" vs "memory" as its backend flips on Redis outage.
type Resource ¶
type Resource interface {
Name() string // unique identifier, e.g. "main-db"
Kind() Kind // database / cache / queue / other
Describe() string // short human description
Healthy() bool // called each time the registry snapshots
Details() map[string]any // free-form (engine, host, version); shown in UI
IsDefault() bool // registry's DefaultOfKind picks this first
}
Resource is anything whose health the dashboard should surface.