adapters

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package adapters holds the sensor service's infrastructure edge: the mock MQTT client used for the demo, the SQL-backed ReadingStore, and the HTTP handler factories. This is the ONLY example package that touches concrete clients — domain and pipeline never import it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCreateHandler

NewCreateHandler returns the POST /readings handler: map request → insert params (domain rule), save, return the stored row.

func NewGetHandler

func NewGetHandler(store *ReadingStore) nethttp.HandlerFunc[struct{}, db.Reading]

NewGetHandler returns the GET /readings/{id} handler.

Types

type MockMQTTClient

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

MockMQTTClient is an in-process pahomqtt.Client that routes published messages straight to registered subscription handlers — no broker needed.

func NewMockMQTTClient

func NewMockMQTTClient() *MockMQTTClient

NewMockMQTTClient returns a ready-to-use in-process MQTT client mock.

func (*MockMQTTClient) AddRoute

func (c *MockMQTTClient) AddRoute(_ string, _ pahomqtt.MessageHandler)

AddRoute implements pahomqtt.Client (no-op).

func (*MockMQTTClient) Connect

func (c *MockMQTTClient) Connect() pahomqtt.Token

Connect implements pahomqtt.Client (no-op success).

func (*MockMQTTClient) Deliver

func (c *MockMQTTClient) Deliver(topic string, payload []byte)

Deliver simulates a sensor publishing a message on topic. It finds the first registered subscription filter that matches the topic, supporting the MQTT '+' single-level wildcard.

func (*MockMQTTClient) Disconnect

func (c *MockMQTTClient) Disconnect(_ uint)

Disconnect implements pahomqtt.Client (no-op).

func (*MockMQTTClient) IsConnected

func (c *MockMQTTClient) IsConnected() bool

IsConnected implements pahomqtt.Client.

func (*MockMQTTClient) IsConnectionOpen

func (c *MockMQTTClient) IsConnectionOpen() bool

IsConnectionOpen implements pahomqtt.Client.

func (*MockMQTTClient) OptionsReader

func (c *MockMQTTClient) OptionsReader() pahomqtt.ClientOptionsReader

OptionsReader implements pahomqtt.Client.

func (*MockMQTTClient) Publish

func (c *MockMQTTClient) Publish(_ string, _ byte, _ bool, _ interface{}) pahomqtt.Token

Publish implements pahomqtt.Client (no-op success).

func (*MockMQTTClient) Subscribe

func (c *MockMQTTClient) Subscribe(topic string, _ byte, h pahomqtt.MessageHandler) pahomqtt.Token

Subscribe implements pahomqtt.Client, registering h for topic.

func (*MockMQTTClient) SubscribeMultiple

func (c *MockMQTTClient) SubscribeMultiple(_ map[string]byte, _ pahomqtt.MessageHandler) pahomqtt.Token

SubscribeMultiple implements pahomqtt.Client (no-op success).

func (*MockMQTTClient) Unsubscribe

func (c *MockMQTTClient) Unsubscribe(_ ...string) pahomqtt.Token

Unsubscribe implements pahomqtt.Client (no-op success).

type ReadingStore

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

ReadingStore wraps the sqlc-generated *db.Queries. It backs the HTTP handlers and the save closure main() binds to the ioports.Readings persistence port — the pipeline itself never sees it.

Every write path calls sqladapter.Validate(domain.InsertParamsCodec, ...) before reaching the DB — the codec rejects invalid data so it never reaches SQL.

Every read path calls sqladapter.Validate(domain.ReadingCodec, ...) after the DB returns a row — defence in depth against data written by other clients that bypassed the codec.

func NewReadingStore

func NewReadingStore(queries *db.Queries) *ReadingStore

NewReadingStore wraps the sqlc-generated queries value.

func (*ReadingStore) Get

func (s *ReadingStore) Get(ctx context.Context, id string) (db.Reading, error)

Get fetches a row and validates it against domain.ReadingCodec.

func (*ReadingStore) Queries

func (s *ReadingStore) Queries() *db.Queries

Queries exposes the raw sqlc queries for read-only demo access (e.g. sql.QueryAdapter's ListReadings poll).

func (*ReadingStore) Save

func (s *ReadingStore) Save(ctx context.Context, params db.InsertReadingParams) error

Save validates params against domain.InsertParamsCodec and inserts the row.

Jump to

Keyboard shortcuts

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