check / check (push) Canceled after 0s
Takes .golangci.yml, .dockerignore, .gitignore, .editorconfig, the workflow and REPO_POLICIES.md from sneak/prompts 0653579, with this repository's own entries after the shared content. Lint (golangci-lint v2.14.0) and test are Dockerfile phases that script/lint and script/test build alone with a new CACHEBUST value, keeping Go's and golangci-lint's caches; the image build depends on both. make fmt and make fmt-check also format the markdown with prettier, pinned in yarn.lock. The agent guidance moves to AGENTS.md. The Go code is fixed for what the new configuration finds, and the AS and prefix detail reads now return the rows' error after their loops. Model: opus-5-5
57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
package routewatch
|
|
|
|
import (
|
|
"slices"
|
|
|
|
"git.eeqj.de/sneak/routewatch/internal/logger"
|
|
"git.eeqj.de/sneak/routewatch/internal/ristypes"
|
|
)
|
|
|
|
// SimpleHandler is a basic implementation of streamer.MessageHandler that
|
|
// filters messages by type and delegates processing to a callback function.
|
|
// It provides a simple way to handle specific RIS message types without
|
|
// implementing the full MessageHandler interface from scratch.
|
|
type SimpleHandler struct {
|
|
logger *logger.Logger
|
|
messageTypes []string
|
|
callback func(*ristypes.RISMessage)
|
|
}
|
|
|
|
// NewSimpleHandler creates a new SimpleHandler that accepts specific message
|
|
// types. The messageTypes parameter specifies which RIS message types this
|
|
// handler will process. If messageTypes is empty, the handler will accept all
|
|
// message types. The callback function is invoked for each message that
|
|
// passes the type filter.
|
|
func NewSimpleHandler(
|
|
logger *logger.Logger,
|
|
messageTypes []string,
|
|
callback func(*ristypes.RISMessage),
|
|
) *SimpleHandler {
|
|
return &SimpleHandler{
|
|
logger: logger,
|
|
messageTypes: messageTypes,
|
|
callback: callback,
|
|
}
|
|
}
|
|
|
|
// WantsMessage returns true if this handler wants to process messages of the
|
|
// given type. It checks whether messageType is in the handler's configured
|
|
// list of accepted types. If no specific types were configured (empty
|
|
// messageTypes slice), it returns true for all types.
|
|
func (h *SimpleHandler) WantsMessage(messageType string) bool {
|
|
// If no specific types are set, accept all messages
|
|
if len(h.messageTypes) == 0 {
|
|
return true
|
|
}
|
|
|
|
return slices.Contains(h.messageTypes, messageType)
|
|
}
|
|
|
|
// HandleMessage processes a RIS message by invoking the configured callback function.
|
|
// If no callback was provided during construction, the message is silently ignored.
|
|
func (h *SimpleHandler) HandleMessage(msg *ristypes.RISMessage) {
|
|
if h.callback != nil {
|
|
h.callback(msg)
|
|
}
|
|
}
|