resource

package
v0.24.2 Latest Latest
Warning

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

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

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind string
const (
	KindDatabase Kind = "database"
	KindCache    Kind = "cache"
	KindQueue    Kind = "queue" // RabbitMQ, Kafka, NATS, etc.
	KindOther    Kind = "other"
)

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

func WithDetails(fn func() map[string]any) Option

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.

func NewCache

func NewCache(name, desc string, details map[string]any, healthy func() bool, opts ...Option) Resource

func NewDatabase

func NewDatabase(name, desc string, details map[string]any, healthy func() bool, opts ...Option) Resource

NewDatabase wraps a connection (e.g. the user's existing DBManager) as a Resource. healthy is called on every dashboard poll — keep it cheap.

func NewQueue

func NewQueue(name, desc string, details map[string]any, healthy func() bool, opts ...Option) Resource

Jump to

Keyboard shortcuts

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