protocol

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package protocol defines the wire records and filters used by DevLogBus.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LevelValue

func LevelValue(level string) int

LevelValue returns the slog-compatible numeric value for a level.

func NormalizeLevel

func NormalizeLevel(level string) string

NormalizeLevel canonicalizes common log-level spellings.

Types

type Envelope

type Envelope struct {
	Type          MessageType    `json:"type"`
	Record        *Record        `json:"record,omitempty"`
	Subscribe     *Subscribe     `json:"subscribe,omitempty"`
	Expunge       *Expunge       `json:"expunge,omitempty"`
	ExpungeResult *ExpungeResult `json:"expungeResult,omitempty"`
	Error         string         `json:"error,omitempty"`
}

Envelope is one newline-delimited JSON message on the broker socket.

type Expunge

type Expunge struct {
	Source string `json:"source,omitempty"`
}

Expunge describes a broker replay-buffer delete request.

type ExpungeResult

type ExpungeResult struct {
	Expunged int `json:"expunged"`
}

ExpungeResult describes the outcome of a replay-buffer delete request.

type MessageType

type MessageType string

MessageType identifies an envelope payload kind.

const (
	// MessageTypeLog carries a structured log record.
	MessageTypeLog MessageType = "log"
	// MessageTypeSubscribe carries a subscription request.
	MessageTypeSubscribe MessageType = "subscribe"
	// MessageTypeReplayComplete marks the end of the initial replay batch.
	MessageTypeReplayComplete MessageType = "replay_complete"
	// MessageTypeExpunge carries a request to delete replay-buffer records.
	MessageTypeExpunge MessageType = "expunge"
	// MessageTypeExpungeResult carries the count of deleted replay-buffer records.
	MessageTypeExpungeResult MessageType = "expunge_result"
	// MessageTypeError carries a broker-side error.
	MessageTypeError MessageType = "error"
)

type Record

type Record struct {
	ID      string         `json:"id,omitempty"`
	Time    time.Time      `json:"time"`
	Level   string         `json:"level"`
	Source  string         `json:"source"`
	Message string         `json:"message"`
	Attrs   map[string]any `json:"attrs,omitempty"`
}

Record is a structured log event.

func (Record) Validate

func (r Record) Validate() error

Validate checks the required record fields.

type Subscribe

type Subscribe struct {
	Sources         []string `json:"sources,omitempty"`
	MinLevel        string   `json:"minLevel,omitempty"`
	Replay          int      `json:"replay,omitempty"`
	ReplayPerSource int      `json:"replayPerSource,omitempty"`
}

Subscribe describes a broker subscription filter.

func (Subscribe) Matches

func (s Subscribe) Matches(record Record) bool

Matches reports whether record satisfies the subscription filter.

Jump to

Keyboard shortcuts

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