event

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package event owns the EventKey registry, RawEvent, APIClient, and dedup filter.

Index

Constants

View Source
const (
	DefaultBufferSize = 100
	MaxBufferSize     = 1000
)

Variables

This section is empty.

Functions

func RegisterKey

func RegisterKey(def KeyDefinition)

RegisterKey panics on duplicate Key, empty EventType, or schema/process contract violations.

func ResetRegistryForTest

func ResetRegistryForTest()

func SanitizeAppID

func SanitizeAppID(appID string) string

SanitizeAppID replaces ".." / path separators / NUL with "_" to guard filepath.Join; empty/dot-only collapses to "_".

func UnregisterKeyForTest

func UnregisterKeyForTest(key string)

UnregisterKeyForTest removes one key — use this (not Reset) in tests with synthetic keys alongside production keys to keep -count=N reruns idempotent.

Types

type APIClient

type APIClient interface {
	CallAPI(ctx context.Context, method, path string, body interface{}) (json.RawMessage, error)
}

APIClient: identity is opaque so business code can't bypass pre-flight checks.

type DedupFilter

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

DedupFilter: seen map is sole authority; ring only bounds map size via overflow eviction.

func NewDedupFilter

func NewDedupFilter() *DedupFilter

func NewDedupFilterWithSize

func NewDedupFilterWithSize(ringSize int, ttl time.Duration) *DedupFilter

func (*DedupFilter) IsDuplicate

func (d *DedupFilter) IsDuplicate(eventID string) bool

type KeyDefinition

type KeyDefinition struct {
	Key         string `json:"key"`
	DisplayName string `json:"display_name,omitempty"`
	Description string `json:"description,omitempty"`
	EventType   string `json:"event_type"`

	Params []ParamDef `json:"params,omitempty"`

	Schema SchemaDef `json:"schema"`

	// Process required when Schema.Custom is Processed output; must be nil when Native is used.
	Process func(ctx context.Context, rt APIClient, raw *RawEvent, params map[string]string) (json.RawMessage, error) `json:"-"`

	PreConsume func(ctx context.Context, rt APIClient, params map[string]string) (cleanup func(), err error) `json:"-"`

	Scopes []string `json:"scopes,omitempty"`

	// AuthTypes: whitelist of identities the EventKey accepts. Empty = no identity required.
	AuthTypes []string `json:"auth_types,omitempty"`

	RequiredConsoleEvents []string `json:"required_console_events,omitempty"`

	BufferSize int `json:"buffer_size,omitempty"`
	Workers    int `json:"workers,omitempty"`
}

func ListAll

func ListAll() []*KeyDefinition

ListAll returns all KeyDefinitions sorted by Key.

func Lookup

func Lookup(key string) (*KeyDefinition, bool)

type ParamDef

type ParamDef struct {
	Name        string       `json:"name"`
	Type        ParamType    `json:"type"`
	Required    bool         `json:"required"`
	Default     string       `json:"default,omitempty"`
	Description string       `json:"description"`
	Values      []ParamValue `json:"values,omitempty"`
}

type ParamType

type ParamType string
const (
	ParamString ParamType = "string"
	ParamEnum   ParamType = "enum"
	ParamMulti  ParamType = "multi"
	ParamBool   ParamType = "bool"
	ParamInt    ParamType = "int"
)

type ParamValue

type ParamValue struct {
	Value string `json:"value"`
	Desc  string `json:"desc"`
}

ParamValue.Desc is mandatory so AI consumers can decide which value to pick.

type ProcessFunc

type ProcessFunc = func(ctx context.Context, rt APIClient, raw *RawEvent, params map[string]string) (json.RawMessage, error)

type RawEvent

type RawEvent struct {
	EventID    string          `json:"event_id"`
	EventType  string          `json:"event_type"`
	SourceTime string          `json:"source_time,omitempty"`
	Payload    json.RawMessage `json:"payload"`
	Timestamp  time.Time       `json:"timestamp"`
}

RawEvent: SourceTime is upstream create_time; Timestamp is local source observation time.

type SchemaDef

type SchemaDef struct {
	Native         *SchemaSpec                  `json:"native,omitempty"`
	Custom         *SchemaSpec                  `json:"custom,omitempty"`
	FieldOverrides map[string]schemas.FieldMeta `json:"field_overrides,omitempty"`
}

SchemaDef: exactly one of Native or Custom must be set. Native auto-wraps the SDK type in the V2 envelope; Custom passes through verbatim.

type SchemaSpec

type SchemaSpec struct {
	Type reflect.Type    `json:"-"`
	Raw  json.RawMessage `json:"raw,omitempty"`
}

SchemaSpec: exactly one of Type or Raw.

Directories

Path Synopsis
Package bus implements the per-AppID event-bus daemon; lifecycle is driven by consumer presence (idle timeout) and explicit shutdown.
Package bus implements the per-AppID event-bus daemon; lifecycle is driven by consumer presence (idle timeout) and explicit shutdown.
Package busctl is the wire-level control client for the event bus daemon.
Package busctl is the wire-level control client for the event bus daemon.
Package busdiscover enumerates live bus daemons via per-AppID PID files protected by a process-lifetime advisory lock.
Package busdiscover enumerates live bus daemons via per-AppID PID files protected by a process-lifetime advisory lock.
Package consume drives the consume-side half of the events pipeline.
Package consume drives the consume-side half of the events pipeline.
Package protocol defines the newline-delimited JSON wire format used over IPC.
Package protocol defines the newline-delimited JSON wire format used over IPC.
Package schemas derives JSON Schema fragments from Go types via reflection.
Package schemas derives JSON Schema fragments from Go types via reflection.
Package source is a pluggable event source abstraction (separate package to keep business registrations free of SDK transitive deps).
Package source is a pluggable event source abstraction (separate package to keep business registrations free of SDK transitive deps).
Package testutil holds test-only helpers shared across event subsystem tests.
Package testutil holds test-only helpers shared across event subsystem tests.
Package transport: Unix sockets on POSIX, named pipes on Windows.
Package transport: Unix sockets on POSIX, named pipes on Windows.

Jump to

Keyboard shortcuts

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