source

package
v0.0.0-...-04431ba Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package source is the Go client for writing sotot sources: programs that watch something and publish the things needing attention to a sotot daemon.

A Client holds the source's desired set of things. The integration updates that set with Set, Upsert, and Remove whenever it learns something, and the Client keeps sotot in sync: a full snapshot on each (re)connection and minimal deltas after that. Because the Client works from the whole desired set rather than a queue of events, a reconnect can't lose changes.

Long-running sources call Run. Sources that run periodically (from cron, say) call PublishOnce, which returns after sotot acknowledges the snapshot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Addr is the tailcat address of this source's sotot listener, as
	// printed by "sotot address". It's a secret: anyone with it can
	// publish as this source.
	Addr string

	// Logf, if non-nil, receives connection status logging.
	Logf func(format string, args ...any)

	// TailcatLogf, if non-nil, receives tailcat's verbose transport
	// logging, which is otherwise discarded.
	TailcatLogf func(format string, args ...any)

	// Dial, if non-nil, overrides how to reach sotot, instead of via
	// tailcat to Addr. It's for tests.
	Dial func(ctx context.Context) (net.Conn, error)

	// PingInterval and PongTimeout control how the client checks that
	// sotot is still there; zero means 30s and 60s.
	PingInterval, PongTimeout time.Duration
	// contains filtered or unexported fields
}

Client publishes things to a sotot daemon.

func NewClientFromEnv

func NewClientFromEnv() (*Client, error)

NewClientFromEnv returns a client for the address in $SOTOT_ADDR, or in the file named by $SOTOT_ADDR_FILE. The address is a secret, so sources should take it from the environment rather than a command-line flag, which other users can see.

func (*Client) Close

func (c *Client) Close() error

Close releases the tailcat transport. Call it after Run or PublishOnce returns.

func (*Client) PublishOnce

func (c *Client) PublishOnce(ctx context.Context) error

PublishOnce connects, publishes the current things as a snapshot, waits for sotot to acknowledge it, and disconnects. Closing the socket alone isn't proof of publication; the ack is.

func (*Client) Refresh

func (c *Client) Refresh()

Refresh renews the validity of the current data, without changing it. Call it when the source has confirmed its data is still accurate, and only then: it's how sotot knows the source is working.

func (*Client) Remove

func (c *Client) Remove(ids ...string)

Remove removes things by ID. Removing an unknown ID is harmless.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run keeps sotot in sync with the client's things until ctx is done, reconnecting with exponential backoff as needed.

func (*Client) Set

func (c *Client) Set(things []protocol.Thing) error

Set replaces the entire set of things.

func (*Client) SetSummary

func (c *Client) SetSummary(s string) error

SetSummary sets a very short description of the source's state, such as "15 domains", which the dashboard shows instead of "Connected". The empty string clears it.

func (*Client) SetValidFor

func (c *Client) SetValidFor(d time.Duration)

SetValidFor sets how long sotot should consider this source's data fresh, counted from when sotot receives it, connected or not. It renews the validity of the current data on the next message.

A long-running source must renew it with Refresh after each successful check, or sotot shows it as stale even while it's connected, as it would be if it were stuck. Choose it from the source's own schedule: a few check intervals, or a little over a day for a source that runs daily. The default is zero: the data becomes stale at once.

func (*Client) Upsert

func (c *Client) Upsert(things ...protocol.Thing) error

Upsert adds or replaces things.

Jump to

Keyboard shortcuts

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