witchesmqtt

package module
v0.0.0-...-e923e0c Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 12 Imported by: 0

README

Internal utilities for witches

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func (*Client) Health

func (c *Client) Health(_ context.Context) Health

type Config

type Config struct {
	// Broker
	BrokerURL    string
	ClientID     string
	Username     string
	Password     string
	KeepAlive    time.Duration
	ConnectRetry time.Duration
	CleanSession bool

	// Behaviour
	QoS            byte   // default 1
	BufferSize     int    // default 512
	MaxConcurrency int    // default 64, 0 = unlimited
	StatusTopic    string // default v1/services/{client_id}/status
	TLS            *TLSConfig
}

type Event

type Event struct {
	DeviceID   string         `json:"device_id"`
	Kind       string         `json:"kind"` // meter.electric | meter.water | status | ...
	Value      float64        `json:"value,omitempty"`
	RoomID     string         `json:"room_id"`
	Unit       string         `json:"unit,omitempty"`
	ReadingAt  time.Time      `json:"reading_at"`
	ReceivedAt time.Time      `json:"received_at"`
	Seq        uint64         `json:"seq,omitempty"`
	Raw        map[string]any `json:"raw,omitempty"`
	Status     string         `json:"status"` // pending | confirmed | disputed
}

type EventBus

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

func NewEventBus

func NewEventBus(handlers ...Handler) *EventBus

func (*EventBus) Publish

func (b *EventBus) Publish(ctx context.Context, e Event) error

func (*EventBus) Subscribe

func (b *EventBus) Subscribe(h Handler)

type Handler

type Handler interface {
	Handle(ctx context.Context, e Event) error
}

type HandlerFunc

type HandlerFunc func(ctx context.Context, e Event) error

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(ctx context.Context, e Event) error

type Health

type Health struct {
	Up         bool   `json:"up"`
	BrokerURL  string `json:"broker_url"`
	ClientID   string `json:"client_id"`
	Subscribed int    `json:"subscribed_patterns"`
}

type ILogger

type ILogger interface {
	Info(msg string)
	Warn(msg string)
	Error(msg string)
	Debug(msg string)
}

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Confirm

func (m *MemoryStore) Confirm(_ context.Context, deviceID string, seq uint64) error

func (*MemoryStore) Pending

func (m *MemoryStore) Pending(_ context.Context, deviceID string) ([]Event, error)

func (*MemoryStore) Save

func (m *MemoryStore) Save(_ context.Context, e Event) error

type Module

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

func Mount

func Mount(cfg Config, opts Options) (*Module, error)

func (*Module) Health

func (m *Module) Health(ctx context.Context) Health

func (*Module) Publish

func (m *Module) Publish(topic string, payload []byte, qos byte, retained bool) error

func (*Module) Run

func (m *Module) Run(ctx context.Context) error

type Options

type Options struct {
	Router *Router
	Bus    *EventBus
	Store  Store
	Logger ILogger
}

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) Dispatch

func (r *Router) Dispatch(ctx context.Context, topic string, payload []byte) error

func (*Router) Handle

func (r *Router) Handle(pattern string, h TopicHandler) *Router

func (*Router) Patterns

func (r *Router) Patterns() []string

type Store

type Store interface {
	Save(ctx context.Context, e Event) error
	Pending(ctx context.Context, deviceID string) ([]Event, error)
	Confirm(ctx context.Context, deviceID string, seq uint64) error
}

type TLSConfig

type TLSConfig struct {
	CAFile   string
	CertFile string
	KeyFile  string
}

type TopicHandler

type TopicHandler func(ctx context.Context, topic string, payload []byte) error

Jump to

Keyboard shortcuts

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