Documentation
¶
Index ¶
- Constants
- Variables
- func CanonicalCommandID(msg any) (string, error)
- func ContextWithDispatchOptions(ctx context.Context, opts DispatchOptions) context.Context
- func ContextWithResult[T any](ctx context.Context, result *Result[T]) context.Context
- func DefaultPanicLogger(funcName string, err any, stack []byte, fields ...map[string]any)
- func GetGoroutineID() uint64
- func GetMessageType(msg any) string
- func IsNilMessage(msg any) bool
- func MakePanicHandler(logger PanicLogger) func(funcName string, fields ...map[string]any)
- func NewQueueMultiHandlerUnsupportedError(commandID string, handlerCount int) *errors.Error
- func NilCronRegister(opts HandlerConfig, handler any) error
- func NilRPCRegister(opts RPCConfig, handler any, meta CommandMeta) error
- func ValidateCommandDispatchRequest(req CommandDispatchRequest) error
- func ValidateCommandDispatchResponse(resp CommandDispatchResponse) error
- func ValidateDedupPolicy(policy DedupPolicy) error
- func ValidateDispatchOptions(effectiveMode ExecutionMode, opts DispatchOptions) error
- func ValidateDispatchReceipt(receipt DispatchReceipt) error
- func ValidateExecutionMode(mode ExecutionMode) error
- func ValidateMessage(msg any) error
- func ValidatePolicyCommandIDs(knownIDs []string, configuredIDs []string) error
- type CLICommand
- type CLIConfig
- type CLIGroup
- type CatalogDescriber
- type CatalogProvider
- type CommandDescriptor
- type CommandDispatchRequest
- type CommandDispatchResponse
- type CommandDispatchValidationError
- type CommandExposure
- type CommandFunc
- type CommandInputField
- type CommandInputSchema
- type CommandInputSchemaProvider
- type CommandMeta
- type CommandOption
- type CommandOptionProvider
- type CommandOptionRequest
- type CommandOptionSourceRef
- type CommandResultDescriptor
- type Commander
- type CronCommand
- type DedupPolicy
- type DispatchOptions
- type DispatchReceipt
- type ExecutionMode
- type ExposableCommand
- type HTTPCommand
- type HandlerConfig
- type Message
- type MessageFactory
- type PanicLogger
- type Querier
- type QueryFunc
- type RPCCommand
- type RPCConfig
- type RPCDescriber
- type RPCDescription
- type Registry
- func (r *Registry) AddResolver(key string, res Resolver) error
- func (r *Registry) CatalogDescriptor(commandID string) (CommandDescriptor, bool)
- func (r *Registry) CatalogDescriptors() []CommandDescriptor
- func (r *Registry) CatalogDescriptorsByExposure(exposed bool) []CommandDescriptor
- func (r *Registry) CatalogDescriptorsByTag(tags ...string) []CommandDescriptor
- func (r *Registry) GetCLIOptions() ([]kong.Option, error)
- func (r *Registry) HasResolver(key string) bool
- func (r *Registry) Initialize() error
- func (r *Registry) RegisterCatalogDescriptor(descriptor CommandDescriptor) error
- func (r *Registry) RegisterCommand(cmd any) error
- func (r *Registry) SetCronRegister(fn func(opts HandlerConfig, handler any) error) *Registry
- func (r *Registry) SetRPCRegister(fn func(opts RPCConfig, handler any, meta CommandMeta) error) *Registry
- type Resolver
- type Result
- type ResultKey
Constants ¶
const ( TextCodeInvalidExecutionMode = "INVALID_EXECUTION_MODE" TextCodeInvalidDedupPolicy = "INVALID_DEDUP_POLICY" TextCodeDispatchOptionsInvalid = "DISPATCH_OPTIONS_INVALID" TextCodeDispatchReceiptInvalid = "DISPATCH_RECEIPT_INVALID" TextCodeUnknownCommandPolicyKey = "UNKNOWN_COMMAND_POLICY_KEY" TextCodeInvalidCommandID = "INVALID_COMMAND_ID" TextCodeQueueMultiHandlerUnsupported = "QUEUE_MULTI_HANDLER_UNSUPPORTED" TextCodeDispatchRequestInvalid = "DISPATCH_REQUEST_INVALID" TextCodeDispatchResponseInvalid = "DISPATCH_RESPONSE_INVALID" )
Variables ¶
var ErrValidation = errors.New("validation error", errors.CategoryValidation).
WithTextCode("VALIDATION_FAILED")
ErrValidation is a sentinel error used to mark validation failures. Wrappers can compare errors with errors.Is(err, ErrValidation) to propagate validation intent through additional layers.
Functions ¶
func CanonicalCommandID ¶ added in v0.17.0
CanonicalCommandID resolves a stable command id for policy/dedup paths. It requires an explicit Type() implementation and does not allow reflection-only fallback ids.
func ContextWithDispatchOptions ¶ added in v0.17.0
func ContextWithDispatchOptions(ctx context.Context, opts DispatchOptions) context.Context
func ContextWithResult ¶ added in v0.3.0
Context helpers
func DefaultPanicLogger ¶ added in v0.2.0
func GetGoroutineID ¶ added in v0.2.0
func GetGoroutineID() uint64
func GetMessageType ¶ added in v0.3.0
func IsNilMessage ¶
func MakePanicHandler ¶ added in v0.2.0
func MakePanicHandler(logger PanicLogger) func(funcName string, fields ...map[string]any)
func NewQueueMultiHandlerUnsupportedError ¶ added in v0.17.0
TODO(BKG_CMD phase 2): enforce this via DispatchWith in queued routing paths.
func NilCronRegister ¶ added in v0.3.0
func NilCronRegister(opts HandlerConfig, handler any) error
func NilRPCRegister ¶ added in v0.15.0
func NilRPCRegister(opts RPCConfig, handler any, meta CommandMeta) error
NilRPCRegister is a noop RPC registration function.
func ValidateCommandDispatchRequest ¶ added in v0.21.0
func ValidateCommandDispatchRequest(req CommandDispatchRequest) error
ValidateCommandDispatchRequest checks the reusable dispatch payload shape.
func ValidateCommandDispatchResponse ¶ added in v0.21.0
func ValidateCommandDispatchResponse(resp CommandDispatchResponse) error
ValidateCommandDispatchResponse checks reusable response and field error shapes without assuming a specific renderer.
func ValidateDedupPolicy ¶ added in v0.17.0
func ValidateDedupPolicy(policy DedupPolicy) error
func ValidateDispatchOptions ¶ added in v0.17.0
func ValidateDispatchOptions(effectiveMode ExecutionMode, opts DispatchOptions) error
func ValidateDispatchReceipt ¶ added in v0.17.0
func ValidateDispatchReceipt(receipt DispatchReceipt) error
func ValidateExecutionMode ¶ added in v0.17.0
func ValidateExecutionMode(mode ExecutionMode) error
func ValidateMessage ¶ added in v0.3.0
func ValidatePolicyCommandIDs ¶ added in v0.17.0
Types ¶
type CLICommand ¶ added in v0.3.0
type CLIConfig ¶ added in v0.3.0
type CatalogDescriber ¶ added in v0.21.0
type CatalogDescriber interface {
CommandDescriptor() CommandDescriptor
}
CatalogDescriber lets a command provide its own descriptor.
type CatalogProvider ¶ added in v0.21.0
type CatalogProvider interface {
CommandDescriptors() []CommandDescriptor
}
CatalogProvider lets hosts provide descriptors externally.
type CommandDescriptor ¶ added in v0.21.0
type CommandDescriptor struct {
ID string `json:"id"`
MessageType string `json:"message_type,omitempty"`
Label string `json:"label,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
Group string `json:"group,omitempty"`
Tags []string `json:"tags,omitempty"`
ExposeInAdmin bool `json:"expose_in_admin,omitempty"`
Mutating bool `json:"mutating,omitempty"`
ExecutionMode ExecutionMode `json:"execution_mode,omitempty"`
Permissions []string `json:"permissions,omitempty"`
Roles []string `json:"roles,omitempty"`
Exposure CommandExposure `json:"exposure,omitempty"`
RPC RPCConfig `json:"rpc,omitempty"`
Input CommandInputSchema `json:"input,omitempty"`
Result CommandResultDescriptor `json:"result,omitempty"`
DisplayHints map[string]any `json:"display_hints,omitempty"`
RedactionHints []string `json:"redaction_hints,omitempty"`
}
CommandDescriptor is the reusable command catalog contract. It describes an intentionally exposed command without importing an admin UI or transport.
func DescriptorForCommand ¶ added in v0.21.0
func DescriptorForCommand(cmd any, meta CommandMeta) (CommandDescriptor, bool)
DescriptorForCommand returns the merged descriptor for an exposed command.
func MergeCommandDescriptor ¶ added in v0.21.0
func MergeCommandDescriptor(meta CommandMeta, exposure CommandExposure, rpcConfig RPCConfig, explicit CommandDescriptor) CommandDescriptor
MergeCommandDescriptor composes message, exposure, RPC, and explicit descriptor metadata. Explicit descriptor fields take precedence.
type CommandDispatchRequest ¶ added in v0.21.0
type CommandDispatchRequest struct {
CommandID string `json:"command_id,omitempty"`
Name string `json:"name,omitempty"`
Payload map[string]any `json:"payload,omitempty"`
IDs []string `json:"ids,omitempty"`
Options DispatchOptions `json:"options,omitempty"`
}
CommandDispatchRequest is the canonical generic command dispatch payload. Transports should wrap this in rpc.RequestEnvelope.
func (CommandDispatchRequest) ResolvedCommandID ¶ added in v0.21.0
func (r CommandDispatchRequest) ResolvedCommandID() string
ResolvedCommandID returns the stable command id, accepting Name only as a compatibility alias for older admin dispatch callers.
type CommandDispatchResponse ¶ added in v0.21.0
type CommandDispatchResponse struct {
Receipt DispatchReceipt `json:"receipt"`
Result any `json:"result,omitempty"`
StatusReference string `json:"status_reference,omitempty"`
ValidationErrors []CommandDispatchValidationError `json:"validation_errors,omitempty"`
}
CommandDispatchResponse is the canonical generic command dispatch response. Transports should wrap this in rpc.ResponseEnvelope.
type CommandDispatchValidationError ¶ added in v0.21.0
type CommandDispatchValidationError struct {
Path string `json:"path,omitempty"`
Code string `json:"code,omitempty"`
Message string `json:"message"`
Details map[string]any `json:"details,omitempty"`
}
CommandDispatchValidationError is safe for browser display and preserves a payload path so renderers can map validation failures to fields.
type CommandExposure ¶ added in v0.13.0
type CommandExposure struct {
// ExposeInAdmin signals this command can be listed in go-admin UI/REPL.
ExposeInAdmin bool
// Tags for grouping/filtering in UI (e.g. "debug", "ops").
Tags []string
// Permissions required to execute (admin will enforce).
// If empty, consumers should derive defaults from Mutates.
Permissions []string
// Roles allowed to execute (optional).
Roles []string
// Mutates signals side effects; false implies read-only.
Mutates bool
}
CommandExposure declares optional UI/REPL exposure metadata. The zero value is safe: ExposeInAdmin is false and Mutates is read-only.
func ExposureOf ¶ added in v0.13.0
func ExposureOf(cmd any) (CommandExposure, bool)
ExposureOf returns exposure metadata if cmd implements ExposableCommand.
type CommandFunc ¶
CommandFunc is an adapter that lets you use a function as a CommandHandler[T]
type CommandInputField ¶ added in v0.21.0
type CommandInputField struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Path string `json:"path"`
Label string `json:"label,omitempty"`
Kind string `json:"kind,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Required bool `json:"required,omitempty"`
Default any `json:"default,omitempty"`
Placeholder string `json:"placeholder,omitempty"`
Description string `json:"description,omitempty"`
Help string `json:"help,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
StaticOptions []CommandOption `json:"static_options,omitempty"`
OptionSource *CommandOptionSourceRef `json:"option_source,omitempty"`
Validation map[string]any `json:"validation,omitempty"`
DisplayHints map[string]any `json:"display_hints,omitempty"`
}
CommandInputField describes one stable payload target.
type CommandInputSchema ¶ added in v0.21.0
type CommandInputSchema struct {
Type string `json:"type,omitempty"`
Fields []CommandInputField `json:"fields,omitempty"`
Required []string `json:"required,omitempty"`
JSONSchema map[string]any `json:"json_schema,omitempty"`
Extensions map[string]any `json:"extensions,omitempty"`
NoInput bool `json:"no_input,omitempty"`
}
CommandInputSchema is a renderer-neutral, JSON Schema/OpenAPI-compatible payload description. Consumers can translate it to go-formgen or another UI.
func CommandInputSchemaFromMessage ¶ added in v0.21.0
func CommandInputSchemaFromMessage(msg any) CommandInputSchema
CommandInputSchemaFromMessage derives a minimal payload schema from exported struct fields. Sensitive fields marked with catalog:"sensitive" or command:"sensitive" are intentionally skipped.
type CommandInputSchemaProvider ¶ added in v0.21.0
type CommandInputSchemaProvider interface {
CommandInputSchema() CommandInputSchema
}
CommandInputSchemaProvider lets a command provide late-bound schema metadata without coupling to a renderer.
type CommandMeta ¶ added in v0.11.0
func MessageTypeForCommand ¶ added in v0.11.0
func MessageTypeForCommand(cmd any) CommandMeta
type CommandOption ¶ added in v0.21.0
type CommandOption struct {
Value string `json:"value"`
Label string `json:"label,omitempty"`
Description string `json:"description,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
CommandOption is a safe static option value.
type CommandOptionProvider ¶ added in v0.21.0
type CommandOptionProvider interface {
CommandOptions(context.Context, CommandOptionRequest) ([]CommandOption, error)
}
CommandOptionProvider resolves request-scoped option values without coupling go-command descriptors to an admin UI or transport.
type CommandOptionRequest ¶ added in v0.21.0
type CommandOptionRequest struct {
CommandID string `json:"command_id"`
FieldID string `json:"field_id,omitempty"`
FieldName string `json:"field_name,omitempty"`
FieldPath string `json:"field_path,omitempty"`
Source CommandOptionSourceRef `json:"source"`
Payload map[string]any `json:"payload,omitempty"`
}
CommandOptionRequest identifies one request-scoped option lookup. Consumers authorize discovery before invoking a provider.
type CommandOptionSourceRef ¶ added in v0.21.0
type CommandOptionSourceRef struct {
ID string `json:"id"`
Label string `json:"label,omitempty"`
Dynamic bool `json:"dynamic,omitempty"`
CacheScope string `json:"cache_scope,omitempty"`
RedactionHint string `json:"redaction_hint,omitempty"`
Params map[string]any `json:"params,omitempty"`
}
CommandOptionSourceRef references request-scoped dynamic options without serializing the option values in the descriptor.
type CommandResultDescriptor ¶ added in v0.21.0
type CommandResultDescriptor struct {
Inline bool `json:"inline,omitempty"`
Queued bool `json:"queued,omitempty"`
StatusReference string `json:"status_reference,omitempty"`
ReceiptExpected bool `json:"receipt_expected,omitempty"`
ResultSchema map[string]any `json:"result_schema,omitempty"`
RedactionHints []string `json:"redaction_hints,omitempty"`
DisplayHints map[string]any `json:"display_hints,omitempty"`
}
CommandResultDescriptor declares the safe result/receipt expectations.
type CronCommand ¶ added in v0.3.0
type CronCommand interface {
CronHandler() func() error
CronOptions() HandlerConfig
}
type DedupPolicy ¶ added in v0.17.0
type DedupPolicy string
const ( DedupPolicyIgnore DedupPolicy = "ignore" DedupPolicyDrop DedupPolicy = "drop" DedupPolicyMerge DedupPolicy = "merge" DedupPolicyReplace DedupPolicy = "replace" )
func NormalizeDedupPolicy ¶ added in v0.17.0
func NormalizeDedupPolicy(policy DedupPolicy) DedupPolicy
func ParseDedupPolicy ¶ added in v0.17.0
func ParseDedupPolicy(raw string) (DedupPolicy, error)
type DispatchOptions ¶ added in v0.17.0
type DispatchOptions struct {
Mode ExecutionMode
IdempotencyKey string
DedupPolicy DedupPolicy
Delay time.Duration
RunAt *time.Time
CorrelationID string
Metadata map[string]any
}
func DispatchOptionsFromContext ¶ added in v0.17.0
func DispatchOptionsFromContext(ctx context.Context) (DispatchOptions, bool)
type DispatchReceipt ¶ added in v0.17.0
type ExecutionMode ¶ added in v0.17.0
type ExecutionMode string
const ( ExecutionModeInline ExecutionMode = "inline" ExecutionModeQueued ExecutionMode = "queued" )
func NormalizeExecutionMode ¶ added in v0.17.0
func NormalizeExecutionMode(mode ExecutionMode) ExecutionMode
func ParseExecutionMode ¶ added in v0.17.0
func ParseExecutionMode(raw string) (ExecutionMode, error)
type ExposableCommand ¶ added in v0.13.0
type ExposableCommand interface {
Exposure() CommandExposure
}
ExposableCommand can be implemented by CLICommand (or any Command/Query). Opt-in is explicit: consumers should ignore commands that do not implement it or return ExposeInAdmin=false.
type HTTPCommand ¶ added in v0.3.0
type HTTPCommand interface {
HTTPHandler()
}
type HandlerConfig ¶ added in v0.3.0
type Message ¶
type Message interface {
Type() string
}
Message is the interface command and queries messages must implement
type MessageFactory ¶ added in v0.11.0
type MessageFactory interface {
MessageValue() any
}
MessageFactory provides a concrete message value for interface-based commands.
type PanicLogger ¶ added in v0.2.0
type RPCCommand ¶ added in v0.15.0
RPCCommand allows commands/queries to opt into RPC registration.
type RPCConfig ¶ added in v0.15.0
type RPCConfig struct {
// Method is the RPC method name, e.g. "fsm.apply_event".
Method string
// Timeout is an optional transport timeout hint.
Timeout time.Duration
// Streaming declares whether this endpoint is stream oriented.
Streaming bool
// Idempotent declares whether retries are generally safe.
Idempotent bool
// Permissions required to invoke this method.
Permissions []string
// Roles allowed to invoke this method.
Roles []string
// Summary is a short endpoint description for docs/discovery.
Summary string
// Description is a longer endpoint description for docs/discovery.
Description string
// Tags groups endpoint in generated clients/docs.
Tags []string
// Deprecated marks endpoint for phased removal.
Deprecated bool
// Since captures the version this endpoint was introduced.
Since string
}
RPCConfig declares optional transport level metadata for RPC exposure. The zero value is safe and keeps behavior minimally configured.
type RPCDescriber ¶ added in v0.15.0
type RPCDescriber interface {
RPCDescription() RPCDescription
}
RPCDescriber allows commands to expose richer endpoint metadata for docs/codegen. This is optional and only used by RPC resolver paths.
type RPCDescription ¶ added in v0.15.0
type RPCDescription struct {
Summary string
Description string
Tags []string
Deprecated bool
Since string
}
RPCDescription carries optional endpoint documentation metadata.
type Registry ¶ added in v0.3.0
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶ added in v0.3.0
func NewRegistry() *Registry
func (*Registry) AddResolver ¶ added in v0.11.0
func (*Registry) CatalogDescriptor ¶ added in v0.21.0
func (r *Registry) CatalogDescriptor(commandID string) (CommandDescriptor, bool)
CatalogDescriptor returns one descriptor by stable command ID.
func (*Registry) CatalogDescriptors ¶ added in v0.21.0
func (r *Registry) CatalogDescriptors() []CommandDescriptor
CatalogDescriptors returns descriptors in deterministic registration order.
func (*Registry) CatalogDescriptorsByExposure ¶ added in v0.21.0
func (r *Registry) CatalogDescriptorsByExposure(exposed bool) []CommandDescriptor
CatalogDescriptorsByExposure returns descriptors with the requested admin exposure state. It does not perform actor authorization.
func (*Registry) CatalogDescriptorsByTag ¶ added in v0.21.0
func (r *Registry) CatalogDescriptorsByTag(tags ...string) []CommandDescriptor
CatalogDescriptorsByTag returns descriptors matching at least one tag.
func (*Registry) GetCLIOptions ¶ added in v0.3.0
func (*Registry) HasResolver ¶ added in v0.11.0
func (*Registry) Initialize ¶ added in v0.3.0
func (*Registry) RegisterCatalogDescriptor ¶ added in v0.21.0
func (r *Registry) RegisterCatalogDescriptor(descriptor CommandDescriptor) error
RegisterCatalogDescriptor registers or replaces an external catalog descriptor. Duplicate IDs replace in place and preserve original ordering.
func (*Registry) RegisterCommand ¶ added in v0.3.0
func (*Registry) SetCronRegister ¶ added in v0.3.0
func (r *Registry) SetCronRegister(fn func(opts HandlerConfig, handler any) error) *Registry
func (*Registry) SetRPCRegister ¶ added in v0.15.0
type Result ¶ added in v0.3.0
type Result[T any] struct { // contains filtered or unexported fields }
Result collector implementation from before
func ResultFromContext ¶ added in v0.3.0
func (*Result[T]) GetMetadata ¶ added in v0.3.0
func (*Result[T]) StoreError ¶ added in v0.3.0
func (*Result[T]) StoreWithMeta ¶ added in v0.3.0
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
rpc-tsgen
command
|
|
|
examples
|
|
|
flow/batch_processing
command
|
|
|
flow/conditional_guard
command
|
|
|
flow/config_build
command
|
|
|
flow/dispatch_fanout
command
|
|
|
flow/metrics_decorator
command
|
|
|
flow/parallel_error_strategy
command
|
|
|
flow/resilience
command
|
|
|
flow/saga_compensation
command
|
|
|
rpc/tsgen
command
|
|
|
rpc/web_debug
command
|
|