API Reference
server
import "github.com/danmestas/dagnats/server"Index
type Config
Config holds all server configuration.
type Config struct {
DataDir string `json:"data_dir"`
HTTPAddr string `json:"http_addr"`
NATSPort int `json:"nats_port"`
LeafRemotes []string `json:"leaf_remotes"`
LeafCredentials string `json:"leaf_credentials"`
MonitorPort int `json:"monitor_port"`
MaxStoreBytes int64 `json:"max_store_bytes"`
Workers []WorkerConfig `json:"workers"`
}func ConfigFromEnv
func ConfigFromEnv() ConfigConfigFromEnv loads config from defaults, config file, then env vars. Config file is dagnats.yaml in CWD. Missing file is not an error. Panics if DataDir is empty or MaxStoreBytes <= 0 after resolution.
func DefaultConfig
func DefaultConfig() ConfigDefaultConfig returns platform-appropriate defaults. Panics if dataDir resolves empty.
type Server
Server is the all-in-one DagNats server lifecycle manager.
type Server struct {
// contains filtered or unexported fields
}func New
func New(cfg Config) *ServerNew creates a Server with the given config. Panics if DataDir is empty.
func (*Server) Run
func (s *Server) Run() errorRun starts all server components, serves HTTP, and blocks until shutdown. Returns nil on clean shutdown, error otherwise.
func (*Server) Stop
func (s *Server) Stop()Stop closes the stopCh to trigger shutdown. Safe to call multiple times.
type WorkerConfig
WorkerConfig defines a config-driven embedded worker handler.
type WorkerConfig struct {
Task string
Exec string
HTTP string
HTTPMethod string // default: POST
}type WorkerShim
WorkerShim collects handler registrations before the server starts. Returned by EmbeddedWorker(). The shim is materialized to a real *worker.Worker during startComponents().
type WorkerShim struct {
// contains filtered or unexported fields
}func EmbeddedWorker
func EmbeddedWorker(srv *Server) *WorkerShimEmbeddedWorker creates a WorkerShim bound to srv’s lifecycle. Must be called before Run(). Panics if called after Run(), if srv is nil, or if the max embedded worker limit is exceeded.
func (*WorkerShim) Handle
func (s *WorkerShim) Handle(taskType string, handler worker.HandlerFunc)Handle registers a handler for a task type. Panics if called after Run(), if taskType is empty, or if handler is nil.
func (*WorkerShim) WithGroups
func (s *WorkerShim) WithGroups(groups ...string)WithGroups configures this embedded worker for specific worker groups. During materialization, translated to worker.WithGroups(groups…). Panics after Run().
Generated by gomarkdoc