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 ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) PublishOnce(ctx context.Context) error
- func (c *Client) Refresh()
- func (c *Client) Remove(ids ...string)
- func (c *Client) Run(ctx context.Context) error
- func (c *Client) Set(things []protocol.Thing) error
- func (c *Client) SetSummary(s string) error
- func (c *Client) SetValidFor(d time.Duration)
- func (c *Client) Upsert(things ...protocol.Thing) error
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 ¶
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 ¶
Close releases the tailcat transport. Call it after Run or PublishOnce returns.
func (*Client) PublishOnce ¶
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) Run ¶
Run keeps sotot in sync with the client's things until ctx is done, reconnecting with exponential backoff as needed.
func (*Client) SetSummary ¶
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 ¶
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.