events

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 25 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package events 提供 XOps v2 作用域化双层事件流与封闭事件代数和类型(ADR-010 / RFC §3.5–§4.1)。

本包遵循严格的六边形物理隔离边界(由 Go 模块与 xopsvet/archbound 双重强制):

  • 生产代码仅依赖 core/domain/** 与纯内存非 I/O 标准库,物理禁止导入 core/ports、core/osfs、 core/conc、core/internal/** 以及 os/net/syscall/unsafe 等宿主原语;
  • 全包 0 裸 go 语句、0 裸 time.Duration 序列化字段、0 secret.SecretBox 字段与明文泄密路径;
  • 核心组件分为三层正交契约: 1. 封闭事件和类型 Event(12 个不可变指针变体)与严格失败关闭的 Go 1.27 encoding/json/v2 编解码(Deterministic(true)); 2. 单次操作隔离流 OperationStream(确定性 EOF、按事件类差异化 BlockWithContext / CoalesceLatest 背压与纯函数 Fold); 3. 同步失败关闭审计分发抽象 AuditDispatcher(与 core/ports.AuditSink 零耦合,支持 Halted 不可逆熔断) 及有界非阻塞诊断总线 SystemBus(DropAndCount 丢弃计数与确定性关闭)。

Index

Constants

View Source
const (
	EventClassInvalid EventClass = iota
	EventClassAudit
	EventClassOperation
	EventClassProgress
	EventClassSystem
	BackpressureInvalid          BackpressurePolicy = 0
	BackpressureFailClosed       BackpressurePolicy = 1
	BackpressureBlockWithContext BackpressurePolicy = 2
	BackpressureCoalesceLatest   BackpressurePolicy = 3
	BackpressureDropAndCount     BackpressurePolicy = 4
)

EventClass 与 BackpressurePolicy 常量:刻画 ADR-010 作用域双层事件流的事件分类与差异化背压策略。

View Source
const (
	SeverityInvalid          Severity         = 0
	SeverityDebug            Severity         = 1
	SeverityInfo             Severity         = 2
	SeverityWarn             Severity         = 3
	SeverityError            Severity         = 4
	OutputStreamInvalid      OutputStreamKind = 0
	OutputStreamStdout       OutputStreamKind = 1
	OutputStreamStderr       OutputStreamKind = 2
	OutputStreamSystem       OutputStreamKind = 3
	AuditStageInvalid        AuditStage       = 0
	AuditStageAuthorized     AuditStage       = 1
	AuditStageDenied         AuditStage       = 2
	AuditStageNeedApproval   AuditStage       = 3
	AuditStageFinalized      AuditStage       = 4
	AuditStageAbortedByCrash AuditStage       = 5
	AuditStageHalted         AuditStage       = 6
	PoolActionInvalid        PoolEventAction  = 0
	PoolActionDialStarted    PoolEventAction  = 1
	PoolActionDialSucceeded  PoolEventAction  = 2
	PoolActionDialFailed     PoolEventAction  = 3
	PoolActionLeaseAcquired  PoolEventAction  = 4
	PoolActionLeaseReleased  PoolEventAction  = 5
	PoolActionEvicted        PoolEventAction  = 6
	PoolActionRetired        PoolEventAction  = 7
	PoolActionGateHalted     PoolEventAction  = 8
	PoolActionMuxHandover    PoolEventAction  = 9
	DiagnosticScopeInvalid   DiagnosticScope  = 0
	DiagnosticScopePool      DiagnosticScope  = 1
	DiagnosticScopeGate      DiagnosticScope  = 2
	DiagnosticScopeTransport DiagnosticScope  = 3
	DiagnosticScopeMux       DiagnosticScope  = 4
	DiagnosticScopeSFTP      DiagnosticScope  = 5
	DiagnosticScopeTransfer  DiagnosticScope  = 6
	DiagnosticScopeMCP       DiagnosticScope  = 7
	DiagnosticScopeRuntime   DiagnosticScope  = 8
	FSMMachineInvalid        FSMMachineKind   = 0
	FSMMachineVaultSaga      FSMMachineKind   = 1
	FSMMachineApproval       FSMMachineKind   = 2
	FSMMachineTransfer       FSMMachineKind   = 3
	FSMMachineEnsure         FSMMachineKind   = 4
	FSMMachinePendingEnroll  FSMMachineKind   = 5
)

Severity、OutputStreamKind、AuditStage、PoolEventAction、DiagnosticScope 与 FSMMachineKind 枚举常量。

Variables

View Source
var (
	ErrNilContext                    = domi18n.Sentinel(domi18n.KeyEventsNilContext)
	ErrNilReceiver                   = domi18n.Sentinel(domi18n.KeyEventsNilReceiver)
	ErrNilWriter                     = domi18n.Sentinel(domi18n.KeyEventsNilWriter)
	ErrInvalidEvent                  = domi18n.Sentinel(domi18n.KeyEventsInvalidEvent)
	ErrInvalidEventMeta              = domi18n.Sentinel(domi18n.KeyEventsInvalidEventMeta)
	ErrInvalidEventKind              = domi18n.Sentinel(domi18n.KeyEventsInvalidEventKind)
	ErrInvalidEventClass             = domi18n.Sentinel(domi18n.KeyEventsInvalidEventClass)
	ErrInvalidBackpressure           = domi18n.Sentinel(domi18n.KeyEventsInvalidBackpressure)
	ErrInvalidSeverity               = domi18n.Sentinel(domi18n.KeyEventsInvalidSeverity)
	ErrInvalidOutputStream           = domi18n.Sentinel(domi18n.KeyEventsInvalidOutputStream)
	ErrInvalidAuditStage             = domi18n.Sentinel(domi18n.KeyEventsInvalidAuditStage)
	ErrInvalidPoolAction             = domi18n.Sentinel(domi18n.KeyEventsInvalidPoolAction)
	ErrInvalidDiagnosticScope        = domi18n.Sentinel(domi18n.KeyEventsInvalidDiagScope)
	ErrInvalidFSMMachine             = domi18n.Sentinel(domi18n.KeyEventsInvalidFSMMachine)
	ErrUnsupportedEventClass         = domi18n.Sentinel(domi18n.KeyEventsUnsupportedClass)
	ErrOperationMismatch             = domi18n.Sentinel(domi18n.KeyEventsOperationMismatch)
	ErrInvalidStreamConfig           = domi18n.Sentinel(domi18n.KeyEventsInvalidStreamConfig)
	ErrStreamNotInitialized          = domi18n.Sentinel(domi18n.KeyEventsStreamNotInit)
	ErrStreamClosed                  = domi18n.Sentinel(domi18n.KeyEventsStreamClosed)
	ErrInvalidFoldFunc               = domi18n.Sentinel(domi18n.KeyEventsInvalidFoldFunc)
	ErrInvalidAuditConfig            = domi18n.Sentinel(domi18n.KeyEventsInvalidAuditConfig)
	ErrNilAuditWriter                = domi18n.Sentinel(domi18n.KeyEventsNilAuditWriter)
	ErrAuditDispatcherNotInitialized = domi18n.Sentinel(domi18n.KeyEventsAuditDispNotInit)
	ErrAuditHalted                   = domi18n.Sentinel(domi18n.KeyEventsAuditHalted)
	ErrAuditDispatchFailed           = domi18n.Sentinel(domi18n.KeyEventsAuditDispatchFailed)
	ErrInvalidBusConfig              = domi18n.Sentinel(domi18n.KeyEventsInvalidBusConfig)
	ErrBusNotInitialized             = domi18n.Sentinel(domi18n.KeyEventsBusNotInit)
	ErrBusClosed                     = domi18n.Sentinel(domi18n.KeyEventsBusClosed)
	ErrBusSubscriberLimit            = domi18n.Sentinel(domi18n.KeyEventsBusSubscriberLimit)
	ErrSubscriptionNotInitialized    = domi18n.Sentinel(domi18n.KeyEventsSubNotInit)
)

本包导出的不可变哨兵错误集合,均由失败关闭路径返回以便上层通过 errors.Is 精确识别。

Functions

func EqualEvent

func EqualEvent(a, b Event) bool

EqualEvent 按值严格比较两个 Event 是否均有效、变体一致且全部字段完全相等(nil 或无效零值恒返回 false)。

func FoldEvents

func FoldEvents[Acc any](initial Acc, items []Event, fn func(acc Acc, ev Event) (Acc, error)) (Acc, error)

FoldEvents 以纯函数方式按序将事件切片折叠为聚合状态 Acc(ADR-010);遇 nil 函数或无效事件即失败关闭。

func FoldStream

func FoldStream[Acc any](ctx context.Context, stream *OperationStream, initial Acc, fn func(acc Acc, ev Event) (Acc, error)) (Acc, error)

FoldStream 持续消费 OperationStream 直至确定性 EOF,将全部事件按序纯函数折叠为最终聚合状态 Acc。

func MarshalEvent

func MarshalEvent(ev Event) ([]byte, error)

MarshalEvent 以 Go 1.27 encoding/json/v2 规范确定性模式(Deterministic(true))编码任意有效 Event。

func MarshalEventTo

func MarshalEventTo(enc *jsontext.Encoder, ev Event) error

MarshalEventTo 以无条件 Deterministic(true) 规范模式将任意有效 Event 编码至既有 jsontext.Encoder 流。

Types

type ApprovalChallengeEvent

type ApprovalChallengeEvent struct {
	// contains filtered or unexported fields
}

func NewApprovalChallengeEvent

func NewApprovalChallengeEvent(s ApprovalChallengeSpec) (*ApprovalChallengeEvent, error)

NewApprovalChallengeEvent 校验审批信封、审批阶段及 OperationID 严格绑定一致性并构造 *ApprovalChallengeEvent。

func (*ApprovalChallengeEvent) Backpressure

func (e *ApprovalChallengeEvent) Backpressure() BackpressurePolicy

func (*ApprovalChallengeEvent) Class

func (*ApprovalChallengeEvent) CoalesceKey

func (*ApprovalChallengeEvent) CoalesceKey() string

func (*ApprovalChallengeEvent) Envelope

func (*ApprovalChallengeEvent) Escalated

func (e *ApprovalChallengeEvent) Escalated() bool

func (*ApprovalChallengeEvent) IsValid

func (e *ApprovalChallengeEvent) IsValid() bool

func (*ApprovalChallengeEvent) Kind

func (ApprovalChallengeEvent) MarshalJSONTo

func (e ApprovalChallengeEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*ApprovalChallengeEvent) Meta

func (*ApprovalChallengeEvent) Phase

func (*ApprovalChallengeEvent) Reason

func (e *ApprovalChallengeEvent) Reason() string

func (*ApprovalChallengeEvent) UnmarshalJSONFrom

func (e *ApprovalChallengeEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type ApprovalChallengeSpec

type ApprovalChallengeSpec struct {
	Meta      EventMeta
	Envelope  security.ApprovalEnvelope
	Phase     fsm.ApprovalPhase
	Escalated bool
	Reason    string
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type AuditDispatcher

type AuditDispatcher struct {
	// contains filtered or unexported fields
}

AuditDispatcher 是面向安全审计事件流(*AuditRecordEvent)的可选同步 Fail-Closed 分发器(ADR-008 / ADR-010): 零缓冲、零丢弃、零后台协程,绝不持锁调用外部 ctx.Err()/AuditWriter/OnHalt,熔断状态不可逆。

单一熔断所有权边界(ADR-008):在 core/engine 生产装配中,core/internal/gate.Gate 是唯一权威的审计落盘与 Halted 熔断状态机所有者(直接写入 ports.AuditSink 并经 OnHaltFunc 驱动 pool.GateHalted); 本类型仅作事件投影旁路或独立测试组件使用,严禁与 gate.Gate 并行装配为第二套独立熔断状态机。

func NewAuditDispatcher

func NewAuditDispatcher(cfg AuditDispatcherConfig) (*AuditDispatcher, error)

NewAuditDispatcher 校验写入器非空(含拒绝 typed-nil AuditWriterFunc(nil))与可选诊断总线已初始化,构造同步失败关闭的 AuditDispatcher。

func (*AuditDispatcher) Dispatch

func (d *AuditDispatcher) Dispatch(ctx context.Context, ev *AuditRecordEvent) error

Dispatch 同步向底层 AuditWriter 分发有效 *AuditRecordEvent;未初始化、已熔断、ctx 取消或落盘失败均失败关闭。

func (*AuditDispatcher) DispatchEvent

func (d *AuditDispatcher) DispatchEvent(ctx context.Context, ev Event) error

DispatchEvent 经由穷尽 Event type switch 仅放行 *AuditRecordEvent,其余变体一律失败关闭拒绝。

func (*AuditDispatcher) Halt

func (d *AuditDispatcher) Halt(reason string, cause error)

Halt 将分发器不可逆切换至 Halted 熔断态,并在锁外经 haltOnce 线性化至多触发一次 OnHalt 回调。

func (*AuditDispatcher) HaltReason

func (d *AuditDispatcher) HaltReason() string

func (*AuditDispatcher) IsHalted

func (d *AuditDispatcher) IsHalted() bool

IsHalted、HaltReason 与 Stats 返回分发器熔断状态与并发安全统计快照(零值恒返回 Halted=true)。

func (*AuditDispatcher) Stats

type AuditDispatcherConfig

type AuditDispatcherConfig struct {
	Writer           AuditWriter     // 必填底层同步持久化写入器
	HaltOnWriteError bool            // true 时任意同步写失败立即触发不可逆 Halted 熔断
	OnHalt           OnAuditHaltFunc // 可选熔断回调,首次熔断时于锁外同步触发一次
	DiagnosticBus    *SystemBus      // 可选非阻塞诊断总线,仅在写失败时做脱敏旁路镜像
}

AuditDispatcherConfig 定义同步审计分发器 AuditDispatcher 的初始化参数。

type AuditDispatcherStats

type AuditDispatcherStats struct {
	Dispatched, Failed uint64
	Halted             bool
}

AuditDispatcherStats 提供 AuditDispatcher 当前的不可变运行统计快照。

type AuditRecordEvent

type AuditRecordEvent struct {
	// contains filtered or unexported fields
}

func NewAuditRecordEvent

func NewAuditRecordEvent(s AuditRecordSpec) (*AuditRecordEvent, error)

NewAuditRecordEvent 校验审计阶段、进程实例 ID、安全决策/阶段一致性、绑定能力一致性与非负耗时并构造 *AuditRecordEvent。

func (*AuditRecordEvent) Backpressure

func (e *AuditRecordEvent) Backpressure() BackpressurePolicy

func (*AuditRecordEvent) Binding

func (*AuditRecordEvent) Capability

func (e *AuditRecordEvent) Capability() security.CapabilityKind

func (*AuditRecordEvent) Class

func (e *AuditRecordEvent) Class() EventClass

func (*AuditRecordEvent) CoalesceKey

func (*AuditRecordEvent) CoalesceKey() string

func (*AuditRecordEvent) Decision

func (*AuditRecordEvent) Duration

func (e *AuditRecordEvent) Duration() algebraic.Duration

func (*AuditRecordEvent) IsValid

func (e *AuditRecordEvent) IsValid() bool

func (*AuditRecordEvent) Kind

func (e *AuditRecordEvent) Kind() EventKind

func (AuditRecordEvent) MarshalJSONTo

func (e AuditRecordEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*AuditRecordEvent) Meta

func (e *AuditRecordEvent) Meta() EventMeta

func (*AuditRecordEvent) Outcome

func (*AuditRecordEvent) ProcessInstanceID

func (e *AuditRecordEvent) ProcessInstanceID() string

func (*AuditRecordEvent) Reason

func (e *AuditRecordEvent) Reason() string

func (*AuditRecordEvent) Risk

func (*AuditRecordEvent) Stage

func (e *AuditRecordEvent) Stage() AuditStage

func (*AuditRecordEvent) UnmarshalJSONFrom

func (e *AuditRecordEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type AuditRecordSpec

type AuditRecordSpec struct {
	Meta              EventMeta
	Stage             AuditStage
	ProcessInstanceID string
	Capability        security.CapabilityKind
	Decision          security.GuardrailDecision
	Risk              security.RiskLevel
	Binding           algebraic.Option[security.OperationBinding]
	Outcome           algebraic.Option[execution.ExecutionOutcome]
	Duration          algebraic.Duration
	Reason            string
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type AuditStage

type AuditStage uint8

func ParseAuditStage

func ParseAuditStage(s string) (v AuditStage, e error)

func (AuditStage) AppendText

func (s AuditStage) AppendText(b []byte) ([]byte, error)

func (AuditStage) IsValid

func (s AuditStage) IsValid() bool

func (AuditStage) IsZero

func (s AuditStage) IsZero() bool

func (AuditStage) MarshalText

func (s AuditStage) MarshalText() ([]byte, error)

func (AuditStage) String

func (s AuditStage) String() string

func (*AuditStage) UnmarshalText

func (s *AuditStage) UnmarshalText(t []byte) error

type AuditWriter

type AuditWriter interface {
	WriteAudit(ctx context.Context, ev *AuditRecordEvent) error
}

AuditWriter 定义 core/events 侧同步失败关闭审计写入抽象(零缓冲、零后台协程,物理隔离 core/ports)。

type AuditWriterFunc

type AuditWriterFunc func(ctx context.Context, ev *AuditRecordEvent) error

AuditWriterFunc 允许通过普通函数适配 AuditWriter 接口,便于上层零样板桥接 core/ports.AuditSink。

func (AuditWriterFunc) WriteAudit

func (f AuditWriterFunc) WriteAudit(ctx context.Context, ev *AuditRecordEvent) error

type BackpressurePolicy

type BackpressurePolicy uint8

func ParseBackpressurePolicy

func ParseBackpressurePolicy(s string) (v BackpressurePolicy, e error)

func (BackpressurePolicy) AppendText

func (p BackpressurePolicy) AppendText(b []byte) ([]byte, error)

func (BackpressurePolicy) IsValid

func (p BackpressurePolicy) IsValid() bool

func (BackpressurePolicy) IsZero

func (p BackpressurePolicy) IsZero() bool

func (BackpressurePolicy) MarshalText

func (p BackpressurePolicy) MarshalText() ([]byte, error)

func (BackpressurePolicy) String

func (p BackpressurePolicy) String() string

func (*BackpressurePolicy) UnmarshalText

func (p *BackpressurePolicy) UnmarshalText(t []byte) error

type BusDroppedEvent

type BusDroppedEvent struct {
	// contains filtered or unexported fields
}

func NewBusDroppedEvent

func NewBusDroppedEvent(s BusDroppedSpec) (*BusDroppedEvent, error)

NewBusDroppedEvent 校验作用域与单调丢弃计数(delta>0 且 total>=delta)并构造 *BusDroppedEvent。

func (*BusDroppedEvent) Backpressure

func (e *BusDroppedEvent) Backpressure() BackpressurePolicy

func (*BusDroppedEvent) Class

func (e *BusDroppedEvent) Class() EventClass

func (*BusDroppedEvent) CoalesceKey

func (*BusDroppedEvent) CoalesceKey() string

func (*BusDroppedEvent) DroppedDelta

func (e *BusDroppedEvent) DroppedDelta() uint64

func (*BusDroppedEvent) DroppedTotal

func (e *BusDroppedEvent) DroppedTotal() uint64

func (*BusDroppedEvent) IsValid

func (e *BusDroppedEvent) IsValid() bool

func (*BusDroppedEvent) Kind

func (e *BusDroppedEvent) Kind() EventKind

func (BusDroppedEvent) MarshalJSONTo

func (e BusDroppedEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*BusDroppedEvent) Meta

func (e *BusDroppedEvent) Meta() EventMeta

func (*BusDroppedEvent) Reason

func (e *BusDroppedEvent) Reason() string

func (*BusDroppedEvent) Scope

func (e *BusDroppedEvent) Scope() DiagnosticScope

func (*BusDroppedEvent) UnmarshalJSONFrom

func (e *BusDroppedEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type BusDroppedSpec

type BusDroppedSpec struct {
	Meta                       EventMeta
	Scope                      DiagnosticScope
	DroppedTotal, DroppedDelta uint64
	Reason                     string
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type DiagnosticEvent

type DiagnosticEvent struct {
	// contains filtered or unexported fields
}

func NewDiagnosticEvent

func NewDiagnosticEvent(s DiagnosticSpec) (*DiagnosticEvent, error)

NewDiagnosticEvent 校验诊断作用域、严重级别、非空消息与属性表并构造 *DiagnosticEvent。

func (*DiagnosticEvent) Attrs

func (e *DiagnosticEvent) Attrs() map[string]string

func (*DiagnosticEvent) Backpressure

func (e *DiagnosticEvent) Backpressure() BackpressurePolicy

func (*DiagnosticEvent) Class

func (e *DiagnosticEvent) Class() EventClass

func (*DiagnosticEvent) CoalesceKey

func (*DiagnosticEvent) CoalesceKey() string

func (*DiagnosticEvent) Code

func (e *DiagnosticEvent) Code() string

func (*DiagnosticEvent) IsValid

func (e *DiagnosticEvent) IsValid() bool

func (*DiagnosticEvent) Kind

func (e *DiagnosticEvent) Kind() EventKind

func (DiagnosticEvent) MarshalJSONTo

func (e DiagnosticEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*DiagnosticEvent) Message

func (e *DiagnosticEvent) Message() string

func (*DiagnosticEvent) Meta

func (e *DiagnosticEvent) Meta() EventMeta

func (*DiagnosticEvent) Scope

func (e *DiagnosticEvent) Scope() DiagnosticScope

func (*DiagnosticEvent) Severity

func (e *DiagnosticEvent) Severity() Severity

func (*DiagnosticEvent) UnmarshalJSONFrom

func (e *DiagnosticEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type DiagnosticScope

type DiagnosticScope uint8

func ParseDiagnosticScope

func ParseDiagnosticScope(s string) (v DiagnosticScope, e error)

func (DiagnosticScope) AppendText

func (d DiagnosticScope) AppendText(b []byte) ([]byte, error)

func (DiagnosticScope) IsValid

func (d DiagnosticScope) IsValid() bool

func (DiagnosticScope) IsZero

func (d DiagnosticScope) IsZero() bool

func (DiagnosticScope) MarshalText

func (d DiagnosticScope) MarshalText() ([]byte, error)

func (DiagnosticScope) String

func (d DiagnosticScope) String() string

func (*DiagnosticScope) UnmarshalText

func (d *DiagnosticScope) UnmarshalText(t []byte) error

type DiagnosticSpec

type DiagnosticSpec struct {
	Meta          EventMeta
	Scope         DiagnosticScope
	Severity      Severity
	Code, Message string
	Attrs         map[string]string
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type Event

type Event interface {
	Kind() EventKind
	Class() EventClass
	Backpressure() BackpressurePolicy
	CoalesceKey() string
	Meta() EventMeta
	IsValid() bool
	// contains filtered or unexported methods
}

Event 是 XOps v2 全域作用域事件流的封闭代数和类型(ADR-010 / RFC §3.6)。 仅限本包内 12 个不可变指针变体实现,由 xopsvet/sumexhaust 静态强制全仓 type switch 穷尽覆盖与 fail-closed default。

func UnmarshalEvent

func UnmarshalEvent(data []byte) (Event, error)

UnmarshalEvent 从完整 JSON 字节切片严格解码单条多态 Event;拒绝 null、未知变体、缺失/未知字段与尾随内容。

func UnmarshalEventFrom

func UnmarshalEventFrom(dec *jsontext.Decoder) (Event, error)

UnmarshalEventFrom 从 jsontext.Decoder 严格读取并解码一条多态 Event。

type EventClass

type EventClass uint8

func ParseEventClass

func ParseEventClass(s string) (v EventClass, e error)

func (EventClass) AppendText

func (c EventClass) AppendText(b []byte) ([]byte, error)

func (EventClass) DefaultBackpressure

func (c EventClass) DefaultBackpressure() BackpressurePolicy

DefaultBackpressure 返回事件类别对应的默认背压策略;无效类别失败关闭返回 BackpressureInvalid。

func (EventClass) IsValid

func (c EventClass) IsValid() bool

func (EventClass) IsZero

func (c EventClass) IsZero() bool

func (EventClass) MarshalText

func (c EventClass) MarshalText() ([]byte, error)

func (EventClass) String

func (c EventClass) String() string

func (*EventClass) UnmarshalText

func (c *EventClass) UnmarshalText(t []byte) error

type EventEnvelope

type EventEnvelope struct {
	// contains filtered or unexported fields
}

EventEnvelope 是包装多态 Event 的不可变值容器,便于在结构体字段或切片中直接参与 encoding/json/v2 编解码。

func NewEventEnvelope

func NewEventEnvelope(ev Event) (EventEnvelope, error)

NewEventEnvelope 校验事件有效性并封装为不可变 EventEnvelope;nil 或无效零值失败关闭。

func (EventEnvelope) Equal

func (e EventEnvelope) Equal(other EventEnvelope) bool

func (EventEnvelope) Event

func (e EventEnvelope) Event() Event

func (EventEnvelope) IsValid

func (e EventEnvelope) IsValid() bool

func (EventEnvelope) IsZero

func (e EventEnvelope) IsZero() bool

func (EventEnvelope) MarshalJSONTo

func (e EventEnvelope) MarshalJSONTo(enc *jsontext.Encoder) error

func (*EventEnvelope) UnmarshalJSONFrom

func (e *EventEnvelope) UnmarshalJSONFrom(dec *jsontext.Decoder) error

type EventKind

type EventKind uint8
const (
	EventKindInvalid EventKind = iota
	EventKindOperationStarted
	EventKindOperationCompleted
	EventKindOutputChunk
	EventKindStep
	EventKindFSMTransition
	EventKindApprovalChallenge
	EventKindTransferProgress
	EventKindMetricSample
	EventKindAuditRecord
	EventKindPoolState
	EventKindDiagnostic
	EventKindBusDropped
)

EventKind 常量:标识封闭事件和类型 Event 的 12 个具体变体。

func ParseEventKind

func ParseEventKind(s string) (v EventKind, e error)

func (EventKind) AppendText

func (k EventKind) AppendText(b []byte) ([]byte, error)

func (EventKind) IsValid

func (k EventKind) IsValid() bool

全包 9 个失败关闭枚举的 IsValid / IsZero / String / Parse* / TextCodec 统一实现。

func (EventKind) IsZero

func (k EventKind) IsZero() bool

func (EventKind) MarshalText

func (k EventKind) MarshalText() ([]byte, error)

func (EventKind) String

func (k EventKind) String() string

func (*EventKind) UnmarshalText

func (k *EventKind) UnmarshalText(t []byte) error

type EventMeta

type EventMeta struct {
	// contains filtered or unexported fields
}

func NewEventMeta

func NewEventMeta(spec EventMetaSpec) (EventMeta, error)

NewEventMeta 校验 TraceID、RFC 3339 年份范围 [1, 9999] 时间戳以及可选 OperationID/NodeID, 并将时间归一化为去除单调时钟读数的 UTC 时间戳,构造不可变 EventMeta。

func (EventMeta) Equal

func (m EventMeta) Equal(other EventMeta) bool

func (EventMeta) IsValid

func (m EventMeta) IsValid() bool

func (EventMeta) IsZero

func (m EventMeta) IsZero() bool

func (EventMeta) MarshalJSONTo

func (m EventMeta) MarshalJSONTo(enc *jsontext.Encoder) error

MarshalJSONTo 与 UnmarshalJSONFrom 实现 EventMeta 的 Go 1.27 encoding/json/v2 严格失败关闭编解码。

func (EventMeta) NodeID

func (EventMeta) OccurredAt

func (m EventMeta) OccurredAt() time.Time

func (EventMeta) OperationID

func (m EventMeta) OperationID() algebraic.Option[security.OperationID]

func (EventMeta) Seq

func (m EventMeta) Seq() uint64

func (EventMeta) TraceID

func (m EventMeta) TraceID() security.TraceID

func (*EventMeta) UnmarshalJSONFrom

func (m *EventMeta) UnmarshalJSONFrom(dec *jsontext.Decoder) error

func (EventMeta) WithSeq

func (m EventMeta) WithSeq(seq uint64) EventMeta

type EventMetaSpec

type EventMetaSpec struct {
	TraceID     security.TraceID
	OperationID algebraic.Option[security.OperationID]
	OccurredAt  time.Time
	Seq         uint64
	NodeID      algebraic.Option[inventory.NodeID]
}

EventMetaSpec 与 EventMeta 承载所有事件变体共享的不可变链路追踪、UTC 时间戳与可选节点标识元数据;零值恒无效。

type FSMMachineKind

type FSMMachineKind uint8

func ParseFSMMachineKind

func ParseFSMMachineKind(s string) (v FSMMachineKind, e error)

func (FSMMachineKind) AppendText

func (m FSMMachineKind) AppendText(b []byte) ([]byte, error)

func (FSMMachineKind) IsValid

func (m FSMMachineKind) IsValid() bool

func (FSMMachineKind) IsZero

func (m FSMMachineKind) IsZero() bool

func (FSMMachineKind) MarshalText

func (m FSMMachineKind) MarshalText() ([]byte, error)

func (FSMMachineKind) String

func (m FSMMachineKind) String() string

func (*FSMMachineKind) UnmarshalText

func (m *FSMMachineKind) UnmarshalText(t []byte) error

type FSMTransitionEvent

type FSMTransitionEvent struct {
	// contains filtered or unexported fields
}

func NewApprovalTransitionEvent

func NewApprovalTransitionEvent(m EventMeta, from, to fsm.ApprovalPhase, ev fsm.ApprovalEvent, term bool) (*FSMTransitionEvent, error)

func NewEnsureTransitionEvent

func NewEnsureTransitionEvent(m EventMeta, from, to fsm.EnsurePhase, ev fsm.EnsureEvent, term bool) (*FSMTransitionEvent, error)

func NewFSMTransitionEvent

func NewFSMTransitionEvent(s FSMTransitionSpec) (*FSMTransitionEvent, error)

NewFSMTransitionEvent 校验状态机类型及状态/事件标识并构造 *FSMTransitionEvent。

func NewPendingEnrollTransitionEvent

func NewPendingEnrollTransitionEvent(m EventMeta, from, to fsm.PendingEnrollPhase, ev fsm.PendingEnrollEvent, term bool) (*FSMTransitionEvent, error)

func NewTransferTransitionEvent

func NewTransferTransitionEvent(m EventMeta, from, to fsm.TransferStateKind, ev fsm.TransferEvent, term bool) (*FSMTransitionEvent, error)

func NewVaultSagaTransitionEvent

func NewVaultSagaTransitionEvent(m EventMeta, from, to fsm.VaultSagaStateKind, ev fsm.VaultSagaEvent, term bool) (*FSMTransitionEvent, error)

func (*FSMTransitionEvent) Backpressure

func (e *FSMTransitionEvent) Backpressure() BackpressurePolicy

func (*FSMTransitionEvent) Class

func (e *FSMTransitionEvent) Class() EventClass

func (*FSMTransitionEvent) CoalesceKey

func (*FSMTransitionEvent) CoalesceKey() string

func (*FSMTransitionEvent) Detail

func (e *FSMTransitionEvent) Detail() string

func (*FSMTransitionEvent) EventName

func (e *FSMTransitionEvent) EventName() string

func (*FSMTransitionEvent) FromState

func (e *FSMTransitionEvent) FromState() string

func (*FSMTransitionEvent) IsValid

func (e *FSMTransitionEvent) IsValid() bool

func (*FSMTransitionEvent) Kind

func (e *FSMTransitionEvent) Kind() EventKind

func (*FSMTransitionEvent) Machine

func (e *FSMTransitionEvent) Machine() FSMMachineKind

func (FSMTransitionEvent) MarshalJSONTo

func (e FSMTransitionEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*FSMTransitionEvent) Meta

func (e *FSMTransitionEvent) Meta() EventMeta

func (*FSMTransitionEvent) Terminal

func (e *FSMTransitionEvent) Terminal() bool

func (*FSMTransitionEvent) ToState

func (e *FSMTransitionEvent) ToState() string

func (*FSMTransitionEvent) UnmarshalJSONFrom

func (e *FSMTransitionEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type FSMTransitionSpec

type FSMTransitionSpec struct {
	Meta                          EventMeta
	Machine                       FSMMachineKind
	FromState, ToState, EventName string
	Detail                        string
	Terminal                      bool
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type MetricSampleEvent

type MetricSampleEvent struct {
	// contains filtered or unexported fields
}

func NewMetricSampleEvent

func NewMetricSampleEvent(s MetricSampleSpec) (*MetricSampleEvent, error)

NewMetricSampleEvent 校验指标名、有限数值(拒绝 NaN/Inf 并归一化 -0)、非负采样周期与标签表并构造 *MetricSampleEvent。

func (*MetricSampleEvent) Backpressure

func (e *MetricSampleEvent) Backpressure() BackpressurePolicy

func (*MetricSampleEvent) Class

func (e *MetricSampleEvent) Class() EventClass

func (*MetricSampleEvent) CoalesceKey

func (e *MetricSampleEvent) CoalesceKey() string

CoalesceKey 采用显式字节长度前缀帧编码 (Option[NodeID], metricName, sorted labels), 在数学上严格单射,杜绝含 ':', '|', '=' 等字符的跨序列合并碰撞。

func (*MetricSampleEvent) Interval

func (e *MetricSampleEvent) Interval() algebraic.Duration

func (*MetricSampleEvent) IsValid

func (e *MetricSampleEvent) IsValid() bool

func (*MetricSampleEvent) Kind

func (e *MetricSampleEvent) Kind() EventKind

func (*MetricSampleEvent) Labels

func (e *MetricSampleEvent) Labels() map[string]string

func (MetricSampleEvent) MarshalJSONTo

func (e MetricSampleEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*MetricSampleEvent) Meta

func (e *MetricSampleEvent) Meta() EventMeta

func (*MetricSampleEvent) MetricName

func (e *MetricSampleEvent) MetricName() string

func (*MetricSampleEvent) Unit

func (e *MetricSampleEvent) Unit() string

func (*MetricSampleEvent) UnmarshalJSONFrom

func (e *MetricSampleEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

func (*MetricSampleEvent) Value

func (e *MetricSampleEvent) Value() float64

type MetricSampleSpec

type MetricSampleSpec struct {
	Meta             EventMeta
	MetricName, Unit string
	Value            float64
	Interval         algebraic.Duration
	Labels           map[string]string
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type OnAuditHaltFunc

type OnAuditHaltFunc func(reason string, cause error)

OnAuditHaltFunc 为 AuditDispatcher 首次进入不可逆 Halted 熔断态时在锁外触发至多一次的通知回调(ADR-008)。 并发调用 Halt 的调用方均线性化阻塞至 OnHalt 完成,回调内可安全读取 IsHalted/Stats,但不得重入调用 Halt。

type OperationCompletedEvent

type OperationCompletedEvent struct {
	// contains filtered or unexported fields
}

func NewOperationCompletedEvent

func NewOperationCompletedEvent(s OperationCompletedSpec) (*OperationCompletedEvent, error)

NewOperationCompletedEvent 校验非负耗时与结果一致性(严禁降级 OutcomeUnknown)并构造 *OperationCompletedEvent。

func (*OperationCompletedEvent) Backpressure

func (e *OperationCompletedEvent) Backpressure() BackpressurePolicy

func (*OperationCompletedEvent) Capability

func (*OperationCompletedEvent) Class

func (*OperationCompletedEvent) CoalesceKey

func (*OperationCompletedEvent) CoalesceKey() string

func (*OperationCompletedEvent) Code

func (e *OperationCompletedEvent) Code() string

func (*OperationCompletedEvent) Duration

func (*OperationCompletedEvent) IsValid

func (e *OperationCompletedEvent) IsValid() bool

func (*OperationCompletedEvent) Kind

func (OperationCompletedEvent) MarshalJSONTo

func (e OperationCompletedEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*OperationCompletedEvent) Message

func (e *OperationCompletedEvent) Message() string

func (*OperationCompletedEvent) Meta

func (*OperationCompletedEvent) Outcome

func (*OperationCompletedEvent) Succeeded

func (e *OperationCompletedEvent) Succeeded() bool

func (*OperationCompletedEvent) UnmarshalJSONFrom

func (e *OperationCompletedEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type OperationCompletedSpec

type OperationCompletedSpec struct {
	Meta          EventMeta
	Capability    security.CapabilityKind
	Duration      algebraic.Duration
	Outcome       algebraic.Option[execution.ExecutionOutcome]
	Succeeded     bool
	Code, Message string
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type OperationStartedEvent

type OperationStartedEvent struct {
	// contains filtered or unexported fields
}

func NewOperationStartedEvent

func NewOperationStartedEvent(s OperationStartedSpec) (*OperationStartedEvent, error)

NewOperationStartedEvent 校验操作元数据、能力类别与工具动作标识并构造 *OperationStartedEvent。

func (*OperationStartedEvent) Action

func (e *OperationStartedEvent) Action() string

func (*OperationStartedEvent) Backpressure

func (e *OperationStartedEvent) Backpressure() BackpressurePolicy

func (*OperationStartedEvent) Capability

12 个事件变体的不可变只读访问器(全部对 typed-nil 与无效零值失败关闭,切片/映射返回防御性副本)。

func (*OperationStartedEvent) Class

func (e *OperationStartedEvent) Class() EventClass

func (*OperationStartedEvent) CoalesceKey

func (*OperationStartedEvent) CoalesceKey() string

func (*OperationStartedEvent) IsValid

func (e *OperationStartedEvent) IsValid() bool

12 个事件变体的 IsValid / Event 接口方法(与构造器跨字段不变式严格等价,对 typed-nil 与未初始化零值失败关闭)。

func (*OperationStartedEvent) Kind

func (e *OperationStartedEvent) Kind() EventKind

func (OperationStartedEvent) MarshalJSONTo

func (e OperationStartedEvent) MarshalJSONTo(enc *jsontext.Encoder) error

为全部 12 个具体事件变体提供值接收者 MarshalJSONTo 与严格变体匹配的指针接收者 UnmarshalJSONFrom。

func (*OperationStartedEvent) Meta

func (e *OperationStartedEvent) Meta() EventMeta

func (*OperationStartedEvent) PlanDigest

func (*OperationStartedEvent) Summary

func (e *OperationStartedEvent) Summary() string

func (*OperationStartedEvent) Tool

func (e *OperationStartedEvent) Tool() string

func (*OperationStartedEvent) UnmarshalJSONFrom

func (e *OperationStartedEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type OperationStartedSpec

type OperationStartedSpec struct {
	Meta         EventMeta
	Capability   security.CapabilityKind
	Tool, Action string
	PlanDigest   algebraic.Option[plan.PlanDigest]
	Summary      string
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type OperationStream

type OperationStream struct {
	// contains filtered or unexported fields
}

OperationStream 是绑定单次用例调用的隔离事件流(ADR-010),0 裸 go 语句且零外部 I/O 依赖:

  • 单操作隔离:仅接受匹配绑定 TraceID/OperationID 的 operation/progress 事件;
  • 差异化背压:EventClassOperation 走有界环形队列 BlockWithContext,EventClassProgress 按 CoalesceKey 覆盖未消费最新快照(CoalesceLatest),慢渲染器绝不阻塞生产者;
  • 终态锁存与确定性 EOF:入队 *OperationCompletedEvent 后锁存终态并拒绝后续 Emit,消费侧确保先排空 全部残留进度快照再交付 *OperationCompletedEvent,Close() 后排空稳定返回 (nil, false, nil)。

func NewOperationStream

func NewOperationStream(cfg OperationStreamConfig) (*OperationStream, error)

NewOperationStream 校验绑定标识与缓冲配置,创建并初始化一个 OperationStream。

func (*OperationStream) All

All 返回适配 Go 1.27 range-over-func 的延迟顺序迭代视图,持续产出事件直至确定性 EOF 或 ctx 取消。

func (*OperationStream) Close

func (s *OperationStream) Close()

Close、IsClosed 与 Stats 提供操作流幂等关闭、状态查询及线程安全运行统计(零值恒返回 Closed=true)。

func (*OperationStream) Emit

func (s *OperationStream) Emit(ctx context.Context, ev Event) error

Emit 按事件类别背压策略向操作流投递事件;严守锁纪律,绝不持锁调用外部 ctx.Err()。

func (*OperationStream) IsClosed

func (s *OperationStream) IsClosed() bool

func (*OperationStream) Next

func (s *OperationStream) Next(ctx context.Context) (Event, bool, error)

Next 读取下一条事件;流关闭且全部已入队事件与最新进度快照排空后,稳定返回 (nil, false, nil) 确定性 EOF。

func (*OperationStream) OperationID

func (s *OperationStream) OperationID() security.OperationID

func (*OperationStream) Stats

func (*OperationStream) TraceID

func (s *OperationStream) TraceID() security.TraceID

type OperationStreamConfig

type OperationStreamConfig struct {
	TraceID         security.TraceID     // 绑定所属链路追踪标识(必填)
	OperationID     security.OperationID // 绑定独占操作唯一标识(必填)
	OperationBuffer int                  // EventClassOperation 有界环形队列容量(必须 > 0)
	MaxCoalesceKeys int                  // EventClassProgress 未消费键上限;0 使用默认 256,负值失败关闭
}

OperationStreamConfig 定义单次操作隔离事件流 OperationStream 的初始化参数(零裸 time.Duration)。

type OperationStreamStats

type OperationStreamStats struct {
	Published, Delivered, Coalesced          uint64
	BufferedOperations, PendingCoalescedKeys int
	Closed                                   bool
}

OperationStreamStats 提供 OperationStream 当前的不可变运行统计快照。

type OperationSummary

type OperationSummary struct {
	// contains filtered or unexported fields
}

OperationSummary 表示单次操作事件流纯函数折叠产出的不可变摘要;零值恒无效并单调锁存 HasUnknownOutcome。

func FoldOperationStreamSummary

func FoldOperationStreamSummary(ctx context.Context, stream *OperationStream) (OperationSummary, error)

FoldOperationStreamSummary 排空 OperationStream 直至确定性 EOF 并折叠为不可变 OperationSummary。

func FoldOperationSummary

func FoldOperationSummary(items []Event) (OperationSummary, error)

FoldOperationSummary 以纯函数方式将单次操作的事件切片归约为不可变 OperationSummary。

func (OperationSummary) ApprovalChallenges

func (s OperationSummary) ApprovalChallenges() uint64

func (OperationSummary) Completed

func (s OperationSummary) Completed() bool

func (OperationSummary) Duration

func (s OperationSummary) Duration() algebraic.Duration

func (OperationSummary) Equal

Equal 按值严格比对两个 OperationSummary 是否均有效且全部字段完全相等(零值永不相等)。

func (OperationSummary) FSMTransitions

func (s OperationSummary) FSMTransitions() uint64

func (OperationSummary) HasUnknownOutcome

func (s OperationSummary) HasUnknownOutcome() bool

func (OperationSummary) IsValid

func (s OperationSummary) IsValid() bool

func (OperationSummary) IsZero

func (s OperationSummary) IsZero() bool

func (OperationSummary) LatestTransferBytes

func (s OperationSummary) LatestTransferBytes() uint64

func (OperationSummary) OperationID

func (s OperationSummary) OperationID() security.OperationID

func (OperationSummary) OutputBytes

func (s OperationSummary) OutputBytes() uint64

func (OperationSummary) OutputChunks

func (s OperationSummary) OutputChunks() uint64

func (OperationSummary) ProgressUpdates

func (s OperationSummary) ProgressUpdates() uint64

func (OperationSummary) Started

func (s OperationSummary) Started() bool

func (OperationSummary) StepEvents

func (s OperationSummary) StepEvents() uint64

func (OperationSummary) Succeeded

func (s OperationSummary) Succeeded() bool

func (OperationSummary) TotalEvents

func (s OperationSummary) TotalEvents() uint64

func (OperationSummary) TraceID

func (s OperationSummary) TraceID() security.TraceID

type OutputChunkEvent

type OutputChunkEvent struct {
	// contains filtered or unexported fields
}

func NewOutputChunkEvent

func NewOutputChunkEvent(s OutputChunkSpec) (*OutputChunkEvent, error)

NewOutputChunkEvent 校验输出通道与分块上限(<= 1 MiB)并深拷贝载荷构造 *OutputChunkEvent。

func (*OutputChunkEvent) Backpressure

func (e *OutputChunkEvent) Backpressure() BackpressurePolicy

func (*OutputChunkEvent) ChunkIndex

func (e *OutputChunkEvent) ChunkIndex() uint64

func (*OutputChunkEvent) Class

func (e *OutputChunkEvent) Class() EventClass

func (*OutputChunkEvent) CoalesceKey

func (*OutputChunkEvent) CoalesceKey() string

func (*OutputChunkEvent) Data

func (e *OutputChunkEvent) Data() []byte

func (*OutputChunkEvent) IsValid

func (e *OutputChunkEvent) IsValid() bool

func (*OutputChunkEvent) Kind

func (e *OutputChunkEvent) Kind() EventKind

func (OutputChunkEvent) MarshalJSONTo

func (e OutputChunkEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*OutputChunkEvent) Meta

func (e *OutputChunkEvent) Meta() EventMeta

func (*OutputChunkEvent) Stream

func (e *OutputChunkEvent) Stream() OutputStreamKind

func (*OutputChunkEvent) Truncated

func (e *OutputChunkEvent) Truncated() bool

func (*OutputChunkEvent) UnmarshalJSONFrom

func (e *OutputChunkEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type OutputChunkSpec

type OutputChunkSpec struct {
	Meta       EventMeta
	Stream     OutputStreamKind
	ChunkIndex uint64
	Data       []byte
	Truncated  bool
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type OutputStreamKind

type OutputStreamKind uint8

func ParseOutputStreamKind

func ParseOutputStreamKind(s string) (v OutputStreamKind, e error)

func (OutputStreamKind) AppendText

func (o OutputStreamKind) AppendText(b []byte) ([]byte, error)

func (OutputStreamKind) IsValid

func (o OutputStreamKind) IsValid() bool

func (OutputStreamKind) IsZero

func (o OutputStreamKind) IsZero() bool

func (OutputStreamKind) MarshalText

func (o OutputStreamKind) MarshalText() ([]byte, error)

func (OutputStreamKind) String

func (o OutputStreamKind) String() string

func (*OutputStreamKind) UnmarshalText

func (o *OutputStreamKind) UnmarshalText(t []byte) error

type PoolEventAction

type PoolEventAction uint8

func ParsePoolEventAction

func ParsePoolEventAction(s string) (v PoolEventAction, e error)

func (PoolEventAction) AppendText

func (a PoolEventAction) AppendText(b []byte) ([]byte, error)

func (PoolEventAction) IsValid

func (a PoolEventAction) IsValid() bool

func (PoolEventAction) IsZero

func (a PoolEventAction) IsZero() bool

func (PoolEventAction) MarshalText

func (a PoolEventAction) MarshalText() ([]byte, error)

func (PoolEventAction) String

func (a PoolEventAction) String() string

func (*PoolEventAction) UnmarshalText

func (a *PoolEventAction) UnmarshalText(t []byte) error

type PoolStateEvent

type PoolStateEvent struct {
	// contains filtered or unexported fields
}

func NewPoolStateEvent

func NewPoolStateEvent(s PoolStateSpec) (*PoolStateEvent, error)

NewPoolStateEvent 校验连接池动作、可选摘要/端点与非负延迟并构造 *PoolStateEvent。

func (*PoolStateEvent) Action

func (e *PoolStateEvent) Action() PoolEventAction

func (*PoolStateEvent) ActiveLeases

func (e *PoolStateEvent) ActiveLeases() uint32

func (*PoolStateEvent) Backpressure

func (e *PoolStateEvent) Backpressure() BackpressurePolicy

func (*PoolStateEvent) Class

func (e *PoolStateEvent) Class() EventClass

func (*PoolStateEvent) CoalesceKey

func (*PoolStateEvent) CoalesceKey() string

func (*PoolStateEvent) Detail

func (e *PoolStateEvent) Detail() string

func (*PoolStateEvent) Endpoint

func (*PoolStateEvent) Generation

func (e *PoolStateEvent) Generation() uint64

func (*PoolStateEvent) HandleID

func (e *PoolStateEvent) HandleID() algebraic.Option[plan.HandleID]

func (*PoolStateEvent) HandleKind

func (*PoolStateEvent) HopDigest

func (e *PoolStateEvent) HopDigest() algebraic.Option[plan.HopDigest]

func (*PoolStateEvent) IsValid

func (e *PoolStateEvent) IsValid() bool

func (*PoolStateEvent) Kind

func (e *PoolStateEvent) Kind() EventKind

func (*PoolStateEvent) Latency

func (e *PoolStateEvent) Latency() algebraic.Duration

func (PoolStateEvent) MarshalJSONTo

func (e PoolStateEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*PoolStateEvent) Meta

func (e *PoolStateEvent) Meta() EventMeta

func (*PoolStateEvent) PlanDigest

func (e *PoolStateEvent) PlanDigest() algebraic.Option[plan.PlanDigest]

func (*PoolStateEvent) UnmarshalJSONFrom

func (e *PoolStateEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type PoolStateSpec

type PoolStateSpec struct {
	Meta         EventMeta
	Action       PoolEventAction
	PlanDigest   algebraic.Option[plan.PlanDigest]
	HopDigest    algebraic.Option[plan.HopDigest]
	Endpoint     algebraic.Option[netaddr.Endpoint]
	HandleKind   algebraic.Option[plan.HandleKindCode]
	HandleID     algebraic.Option[plan.HandleID]
	Generation   uint64
	ActiveLeases uint32
	Latency      algebraic.Duration
	Detail       string
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type Severity

type Severity uint8

func ParseSeverity

func ParseSeverity(s string) (v Severity, e error)

func (Severity) AppendText

func (s Severity) AppendText(b []byte) ([]byte, error)

func (Severity) IsValid

func (s Severity) IsValid() bool

func (Severity) IsZero

func (s Severity) IsZero() bool

func (Severity) MarshalText

func (s Severity) MarshalText() ([]byte, error)

func (Severity) String

func (s Severity) String() string

func (*Severity) UnmarshalText

func (s *Severity) UnmarshalText(t []byte) error

type StepEvent

type StepEvent struct {
	// contains filtered or unexported fields
}

func NewStepEvent

func NewStepEvent(s StepEventSpec) (*StepEvent, error)

NewStepEvent 校验步骤标识、状态、非负耗时与 Outcome 一致性并构造 *StepEvent。

func (*StepEvent) Backpressure

func (e *StepEvent) Backpressure() BackpressurePolicy

func (*StepEvent) Class

func (e *StepEvent) Class() EventClass

func (*StepEvent) CoalesceKey

func (*StepEvent) CoalesceKey() string

func (*StepEvent) Duration

func (e *StepEvent) Duration() algebraic.Duration

func (*StepEvent) IsValid

func (e *StepEvent) IsValid() bool

func (*StepEvent) Kind

func (e *StepEvent) Kind() EventKind

func (StepEvent) MarshalJSONTo

func (e StepEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*StepEvent) Message

func (e *StepEvent) Message() string

func (*StepEvent) Meta

func (e *StepEvent) Meta() EventMeta

func (*StepEvent) Outcome

func (*StepEvent) PlaybookID

func (e *StepEvent) PlaybookID() algebraic.Option[playbook.PlaybookID]

func (*StepEvent) Status

func (e *StepEvent) Status() playbook.StepStatus

func (*StepEvent) StepID

func (e *StepEvent) StepID() playbook.StepID

func (*StepEvent) UnmarshalJSONFrom

func (e *StepEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type StepEventSpec

type StepEventSpec struct {
	Meta       EventMeta
	PlaybookID algebraic.Option[playbook.PlaybookID]
	StepID     playbook.StepID
	Status     playbook.StepStatus
	Duration   algebraic.Duration
	Outcome    algebraic.Option[execution.ExecutionOutcome]
	Message    string
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

type SystemBus

type SystemBus struct {
	// contains filtered or unexported fields
}

SystemBus 是承载连接池、多路复用与协议脱敏诊断事件的有界非阻塞发布订阅总线(ADR-010):

  • 仅接受 EventClassSystem 事件;
  • DropAndCount 背压:Publish 持读锁向全部活跃订阅者非阻塞扇出,单个慢订阅者满缓冲时立即丢弃并累加两级丢弃计数, 绝不阻塞发布者或连累其他快订阅者;
  • 并发安全关闭:Subscribe / Unsubscribe / Close 持写锁维护订阅表并关闭子通道,彻底消除向已关闭通道发送 panic。

func NewSystemBus

func NewSystemBus(cfg SystemBusConfig) (*SystemBus, error)

NewSystemBus 校验缓冲容量与订阅上限并构造 SystemBus。

func (*SystemBus) Close

func (b *SystemBus) Close()

Close 幂等关闭 SystemBus,拒绝后续 Publish/Subscribe 并确定性关闭全部活跃订阅通道发送 EOF。

func (*SystemBus) IsClosed

func (b *SystemBus) IsClosed() bool

IsClosed 报告总线是否已关闭(nil 或未初始化零值失败关闭返回 true)。

func (*SystemBus) Publish

func (b *SystemBus) Publish(ev Event) error

Publish 以非阻塞 DropAndCount 语义广播一条系统诊断事件;慢订阅者满缓冲立即丢弃计数,绝不阻塞发布者。

func (*SystemBus) Stats

func (b *SystemBus) Stats() SystemBusStats

Stats 返回总线的并发安全运行统计快照。

func (*SystemBus) Subscribe

func (b *SystemBus) Subscribe() (*SystemSubscription, error)

Subscribe 使用总线默认缓冲容量创建独立订阅句柄。

func (*SystemBus) SubscribeWithBuffer

func (b *SystemBus) SubscribeWithBuffer(buffer int) (*SystemSubscription, error)

SubscribeWithBuffer 使用指定正整数缓冲容量创建独立订阅句柄。

type SystemBusConfig

type SystemBusConfig struct {
	DefaultSubscriberBuffer int // Subscribe() 默认分配的有界订阅通道容量,必须大于 0
	MaxSubscribers          int // 可选活跃订阅者上限;0 表示不额外设限,负值失败关闭
}

SystemBusConfig 定义系统诊断与连接池事件总线 SystemBus 的初始化参数(无 time.Duration)。

type SystemBusStats

type SystemBusStats struct {
	Published, Delivered, Dropped uint64
	ActiveSubscribers             int
	Closed                        bool
}

SystemBusStats 提供 SystemBus 当前的不可变运行统计快照。

type SystemSubscription

type SystemSubscription struct {
	// contains filtered or unexported fields
}

SystemSubscription 表示 SystemBus 上的单个隔离有界订阅句柄;零值恒无效并失败关闭。

func (*SystemSubscription) All

All 返回适配 Go 1.27 range-over-func 的延迟顺序迭代视图。

func (*SystemSubscription) Close

func (s *SystemSubscription) Close()

Close 幂等退订并关闭本订阅通道,确保与 Publish/bus.Close 并发执行零竞态零 panic。

func (*SystemSubscription) Delivered

func (s *SystemSubscription) Delivered() uint64

Delivered、Dropped 与 DrainDroppedDelta 返回本订阅者的投递、累计丢弃及增量丢弃计数。

func (*SystemSubscription) DrainDroppedDelta

func (s *SystemSubscription) DrainDroppedDelta() uint64

func (*SystemSubscription) Dropped

func (s *SystemSubscription) Dropped() uint64

func (*SystemSubscription) IsClosed

func (s *SystemSubscription) IsClosed() bool

IsClosed 报告订阅是否已关闭(nil 或未初始化零值失败关闭返回 true)。

func (*SystemSubscription) Next

func (s *SystemSubscription) Next(ctx context.Context) (Event, bool, error)

Next 读取下一条系统事件;订阅或总线关闭且缓冲排空后稳定返回 (nil, false, nil) 确定性 EOF。

type TransferProgressEvent

type TransferProgressEvent struct {
	// contains filtered or unexported fields
}

func NewTransferProgressEvent

func NewTransferProgressEvent(s TransferProgressSpec) (*TransferProgressEvent, error)

NewTransferProgressEvent 校验传输标识、方向、字节边界与非负耗时并构造 *TransferProgressEvent。

func (*TransferProgressEvent) Backpressure

func (e *TransferProgressEvent) Backpressure() BackpressurePolicy

func (*TransferProgressEvent) BytesTransferred

func (e *TransferProgressEvent) BytesTransferred() uint64

func (*TransferProgressEvent) ChunksCompleted

func (e *TransferProgressEvent) ChunksCompleted() uint64

func (*TransferProgressEvent) Class

func (e *TransferProgressEvent) Class() EventClass

func (*TransferProgressEvent) CoalesceKey

func (e *TransferProgressEvent) CoalesceKey() string

func (*TransferProgressEvent) Direction

func (*TransferProgressEvent) Elapsed

func (*TransferProgressEvent) IsValid

func (e *TransferProgressEvent) IsValid() bool

func (*TransferProgressEvent) Kind

func (e *TransferProgressEvent) Kind() EventKind

func (TransferProgressEvent) MarshalJSONTo

func (e TransferProgressEvent) MarshalJSONTo(enc *jsontext.Encoder) error

func (*TransferProgressEvent) Meta

func (e *TransferProgressEvent) Meta() EventMeta

func (*TransferProgressEvent) RateBytesPerSec

func (e *TransferProgressEvent) RateBytesPerSec() uint64

func (*TransferProgressEvent) Stage

func (e *TransferProgressEvent) Stage() string

func (*TransferProgressEvent) TotalBytes

func (e *TransferProgressEvent) TotalBytes() uint64

func (*TransferProgressEvent) TransferID

func (e *TransferProgressEvent) TransferID() security.OperationID

func (*TransferProgressEvent) UnmarshalJSONFrom

func (e *TransferProgressEvent) UnmarshalJSONFrom(d *jsontext.Decoder) error

type TransferProgressSpec

type TransferProgressSpec struct {
	Meta                                          EventMeta
	TransferID                                    security.OperationID
	Direction                                     fsm.TransferDirection
	BytesTransferred, TotalBytes, ChunksCompleted uint64
	Elapsed                                       algebraic.Duration
	RateBytesPerSec                               uint64
	Stage                                         string
}

12 个封闭事件变体的构造输入规格与不可变不透明结构体(全私有字段 + 正向门控 valid bool,零值恒失败关闭)。

Jump to

Keyboard shortcuts

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