Documentation ¶
Index ¶
- type Client
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) Closed() bool
- func (c *Client) Query(ctx context.Context, q *sdp.Query) ([]*sdp.Item, error)
- func (c *Client) SendQuery(ctx context.Context, q *sdp.Query) error
- func (c *Client) SendStoreBookmark(ctx context.Context, b *sdp.StoreBookmark) error
- func (c *Client) SendStoreSnapshot(ctx context.Context, s *sdp.StoreSnapshot) error
- func (c *Client) StoreBookmark(ctx context.Context, name, description string, isSystem bool) (uuid.UUID, error)
- func (c *Client) StoreSnapshot(ctx context.Context, name, description string) (uuid.UUID, error)
- func (c *Client) Wait(ctx context.Context, reqIDs uuid.UUIDs) error
- type GatewayMessageHandler
- type LoggingGatewayMessageHandler
- func (l *LoggingGatewayMessageHandler) BookmarkLoadResult(ctx context.Context, result *sdp.BookmarkLoadResult)
- func (l *LoggingGatewayMessageHandler) BookmarkStoreResult(ctx context.Context, result *sdp.BookmarkStoreResult)
- func (l *LoggingGatewayMessageHandler) DeleteEdge(ctx context.Context, edge *sdp.Edge)
- func (l *LoggingGatewayMessageHandler) DeleteItem(ctx context.Context, reference *sdp.Reference)
- func (l *LoggingGatewayMessageHandler) Error(ctx context.Context, errorMessage string)
- func (l *LoggingGatewayMessageHandler) NewEdge(ctx context.Context, edge *sdp.Edge)
- func (l *LoggingGatewayMessageHandler) NewItem(ctx context.Context, item *sdp.Item)
- func (l *LoggingGatewayMessageHandler) QueryError(ctx context.Context, queryError *sdp.QueryError)
- func (l *LoggingGatewayMessageHandler) QueryStatus(ctx context.Context, status *sdp.QueryStatus)
- func (l *LoggingGatewayMessageHandler) SnapshotLoadResult(ctx context.Context, result *sdp.SnapshotLoadResult)
- func (l *LoggingGatewayMessageHandler) SnapshotStoreResult(ctx context.Context, result *sdp.SnapshotStoreResult)
- func (l *LoggingGatewayMessageHandler) Status(ctx context.Context, status *sdp.GatewayRequestStatus)
- func (l *LoggingGatewayMessageHandler) UpdateItem(ctx context.Context, item *sdp.Item)
- type NoopGatewayMessageHandler
- func (l *NoopGatewayMessageHandler) BookmarkLoadResult(ctx context.Context, result *sdp.BookmarkLoadResult)
- func (l *NoopGatewayMessageHandler) BookmarkStoreResult(ctx context.Context, result *sdp.BookmarkStoreResult)
- func (l *NoopGatewayMessageHandler) DeleteEdge(ctx context.Context, edge *sdp.Edge)
- func (l *NoopGatewayMessageHandler) DeleteItem(ctx context.Context, reference *sdp.Reference)
- func (l *NoopGatewayMessageHandler) Error(ctx context.Context, errorMessage string)
- func (l *NoopGatewayMessageHandler) NewEdge(ctx context.Context, edge *sdp.Edge)
- func (l *NoopGatewayMessageHandler) NewItem(ctx context.Context, item *sdp.Item)
- func (l *NoopGatewayMessageHandler) QueryError(ctx context.Context, queryError *sdp.QueryError)
- func (l *NoopGatewayMessageHandler) QueryStatus(ctx context.Context, status *sdp.QueryStatus)
- func (l *NoopGatewayMessageHandler) SnapshotLoadResult(ctx context.Context, result *sdp.SnapshotLoadResult)
- func (l *NoopGatewayMessageHandler) SnapshotStoreResult(ctx context.Context, result *sdp.SnapshotStoreResult)
- func (l *NoopGatewayMessageHandler) Status(ctx context.Context, status *sdp.GatewayRequestStatus)
- func (l *NoopGatewayMessageHandler) UpdateItem(ctx context.Context, item *sdp.Item)
- type StoreEverythingHandler
- type WaitForAllQueriesHandler
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
}
Client is the main driver for all interactions with a SDP/Gateway websocket.
Internally it holds a map of all active requests, which are identified by a UUID, to multiplex incoming responses to the correct caller. Note that the request methods block until the response is received, so to send multiple requests in parallel, call requestor methods in goroutines, e.g. using a conc Pool:
```
pool := pool.New().WithContext(ctx).WithCancelOnError().WithFirstError() pool.Go(func() error { items, err := client.Query(ctx, q) if err != nil { return err } // do something with items } // ... pool.Wait()
```
Alternatively, pass in a GatewayMessageHandler to receive all messages as they come in and send messages directly using `Send()` and then `Wait()` for all request IDs.
func Dial ¶
func Dial(ctx context.Context, u string, httpClient *http.Client, handler GatewayMessageHandler) (*Client, error)
Dial connects to the given URL and returns a new Client. Pass nil as handler if you do not need per-message callbacks.
To stop the client, cancel the provided context:
``` ctx, cancel := context.WithCancel(context.Background()) defer cancel() client, err := sdpws.Dial(ctx, gatewayUrl, NewAuthenticatedClient(ctx, otelhttp.DefaultClient), nil) ```
func (*Client) Close ¶
Close closes the connection and returns any errors from the underlying connection.
func (*Client) Query ¶
Run a query and wait for it to complete, returning all of the items that were found.
func (*Client) SendQuery ¶
Sends a query on the websocket connection without waiting for responses. Use the `Wait()` method to wait for completion of requests based on their UUID
func (*Client) SendStoreBookmark ¶
Sends a StoreBookmark request on the websocket connection without waiting for a response.
func (*Client) SendStoreSnapshot ¶
Sends a StoreSnapshot request on the websocket connection without waiting for a response.
func (*Client) StoreBookmark ¶
func (c *Client) StoreBookmark(ctx context.Context, name, description string, isSystem bool) (uuid.UUID, error)
Store a bookmark and wait for it to complete, returning the UUID of the bookmark that was created.
func (*Client) StoreSnapshot ¶
Store a snapshot and wait for it to complete, returning the UUID of the snapshot that was created.
type GatewayMessageHandler ¶
type GatewayMessageHandler interface { NewItem(context.Context, *sdp.Item) NewEdge(context.Context, *sdp.Edge) Status(context.Context, *sdp.GatewayRequestStatus) Error(context.Context, string) QueryError(context.Context, *sdp.QueryError) DeleteItem(context.Context, *sdp.Reference) DeleteEdge(context.Context, *sdp.Edge) UpdateItem(context.Context, *sdp.Item) SnapshotStoreResult(context.Context, *sdp.SnapshotStoreResult) SnapshotLoadResult(context.Context, *sdp.SnapshotLoadResult) BookmarkStoreResult(context.Context, *sdp.BookmarkStoreResult) BookmarkLoadResult(context.Context, *sdp.BookmarkLoadResult) QueryStatus(context.Context, *sdp.QueryStatus) }
GatewayMessageHandler is an interface that can be implemented to handle messages from the gateway. The individual methods are calles when the sdpws client receives a message from the gateway. Methods are called in the same order as the messages are received from the gateway. The sdpws client guarantees that the methods are called in a single thread, so no locking is needed.
type LoggingGatewayMessageHandler ¶
func (*LoggingGatewayMessageHandler) BookmarkLoadResult ¶
func (l *LoggingGatewayMessageHandler) BookmarkLoadResult(ctx context.Context, result *sdp.BookmarkLoadResult)
func (*LoggingGatewayMessageHandler) BookmarkStoreResult ¶
func (l *LoggingGatewayMessageHandler) BookmarkStoreResult(ctx context.Context, result *sdp.BookmarkStoreResult)
func (*LoggingGatewayMessageHandler) DeleteEdge ¶
func (l *LoggingGatewayMessageHandler) DeleteEdge(ctx context.Context, edge *sdp.Edge)
func (*LoggingGatewayMessageHandler) DeleteItem ¶
func (l *LoggingGatewayMessageHandler) DeleteItem(ctx context.Context, reference *sdp.Reference)
func (*LoggingGatewayMessageHandler) Error ¶
func (l *LoggingGatewayMessageHandler) Error(ctx context.Context, errorMessage string)
func (*LoggingGatewayMessageHandler) NewEdge ¶
func (l *LoggingGatewayMessageHandler) NewEdge(ctx context.Context, edge *sdp.Edge)
func (*LoggingGatewayMessageHandler) NewItem ¶
func (l *LoggingGatewayMessageHandler) NewItem(ctx context.Context, item *sdp.Item)
func (*LoggingGatewayMessageHandler) QueryError ¶
func (l *LoggingGatewayMessageHandler) QueryError(ctx context.Context, queryError *sdp.QueryError)
func (*LoggingGatewayMessageHandler) QueryStatus ¶
func (l *LoggingGatewayMessageHandler) QueryStatus(ctx context.Context, status *sdp.QueryStatus)
func (*LoggingGatewayMessageHandler) SnapshotLoadResult ¶
func (l *LoggingGatewayMessageHandler) SnapshotLoadResult(ctx context.Context, result *sdp.SnapshotLoadResult)
func (*LoggingGatewayMessageHandler) SnapshotStoreResult ¶
func (l *LoggingGatewayMessageHandler) SnapshotStoreResult(ctx context.Context, result *sdp.SnapshotStoreResult)
func (*LoggingGatewayMessageHandler) Status ¶
func (l *LoggingGatewayMessageHandler) Status(ctx context.Context, status *sdp.GatewayRequestStatus)
func (*LoggingGatewayMessageHandler) UpdateItem ¶
func (l *LoggingGatewayMessageHandler) UpdateItem(ctx context.Context, item *sdp.Item)
type NoopGatewayMessageHandler ¶
type NoopGatewayMessageHandler struct{}
func (*NoopGatewayMessageHandler) BookmarkLoadResult ¶
func (l *NoopGatewayMessageHandler) BookmarkLoadResult(ctx context.Context, result *sdp.BookmarkLoadResult)
func (*NoopGatewayMessageHandler) BookmarkStoreResult ¶
func (l *NoopGatewayMessageHandler) BookmarkStoreResult(ctx context.Context, result *sdp.BookmarkStoreResult)
func (*NoopGatewayMessageHandler) DeleteEdge ¶
func (l *NoopGatewayMessageHandler) DeleteEdge(ctx context.Context, edge *sdp.Edge)
func (*NoopGatewayMessageHandler) DeleteItem ¶
func (l *NoopGatewayMessageHandler) DeleteItem(ctx context.Context, reference *sdp.Reference)
func (*NoopGatewayMessageHandler) Error ¶
func (l *NoopGatewayMessageHandler) Error(ctx context.Context, errorMessage string)
func (*NoopGatewayMessageHandler) NewEdge ¶
func (l *NoopGatewayMessageHandler) NewEdge(ctx context.Context, edge *sdp.Edge)
func (*NoopGatewayMessageHandler) NewItem ¶
func (l *NoopGatewayMessageHandler) NewItem(ctx context.Context, item *sdp.Item)
func (*NoopGatewayMessageHandler) QueryError ¶
func (l *NoopGatewayMessageHandler) QueryError(ctx context.Context, queryError *sdp.QueryError)
func (*NoopGatewayMessageHandler) QueryStatus ¶
func (l *NoopGatewayMessageHandler) QueryStatus(ctx context.Context, status *sdp.QueryStatus)
func (*NoopGatewayMessageHandler) SnapshotLoadResult ¶
func (l *NoopGatewayMessageHandler) SnapshotLoadResult(ctx context.Context, result *sdp.SnapshotLoadResult)
func (*NoopGatewayMessageHandler) SnapshotStoreResult ¶
func (l *NoopGatewayMessageHandler) SnapshotStoreResult(ctx context.Context, result *sdp.SnapshotStoreResult)
func (*NoopGatewayMessageHandler) Status ¶
func (l *NoopGatewayMessageHandler) Status(ctx context.Context, status *sdp.GatewayRequestStatus)
func (*NoopGatewayMessageHandler) UpdateItem ¶
func (l *NoopGatewayMessageHandler) UpdateItem(ctx context.Context, item *sdp.Item)
type StoreEverythingHandler ¶ added in v0.71.0
type StoreEverythingHandler struct { Items []*sdp.Item Edges []*sdp.Edge NoopGatewayMessageHandler }
A handler that stores all the items and edges it receives
func (*StoreEverythingHandler) NewEdge ¶ added in v0.71.0
func (s *StoreEverythingHandler) NewEdge(ctx context.Context, edge *sdp.Edge)
func (*StoreEverythingHandler) NewItem ¶ added in v0.71.0
func (s *StoreEverythingHandler) NewItem(ctx context.Context, item *sdp.Item)
type WaitForAllQueriesHandler ¶ added in v0.71.0
type WaitForAllQueriesHandler struct { // A callback that will be called when all queries are done DoneCallback func() StoreEverythingHandler }
A Handler that waits for all queries to be done then calls a callback
func (*WaitForAllQueriesHandler) Status ¶ added in v0.71.0
func (w *WaitForAllQueriesHandler) Status(ctx context.Context, status *sdp.GatewayRequestStatus)