Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API interface { // Send sends a status update to the specified URL. // // Parameters: // - ctx: The context.Context used to cancel the operation if needed. // - url: The URL to send the status update to. // - status: The entities.Status to send. // // Returns: // - An error if the status update cannot be sent to the URL. // - nil if the status update was sent successfully. // // Send sends a status update to the specified URL. // It takes a context.Context used to cancel the operation if needed, // a string representing the URL to send the status update to, // and an entities.Status representing the status to send. // It returns an error if the status update cannot be sent to the URL, // and nil if the status update was sent successfully. Send(ctx context.Context, url string, status entities.Status) error }
API represents an interface for sending status updates.
type StateManager ¶
type StateManager struct {
// contains filtered or unexported fields
}
StateManager manages the sending of status updates to webhooks.
The StateManager struct holds the necessary dependencies to manage the sending of status updates to webhooks. It has the following fields:
- api: The API used to send status updates.
- repo: The repository used to get webhook URLs.
- cache: The cache used to store the current status of webhooks.
- mu: The mutex used to synchronize access to the cache.
func NewStateManager ¶
func NewStateManager(api API, repo WebhookRegistry, log *zerolog.Logger) *StateManager
NewStateManager creates a new instance of the StateManager struct.
It takes an API, a WebhookRegistry, and a logger as input parameters. It returns a pointer to the initialized StateManager.
Parameters:
- api: The API used to send status updates.
- repo: The repository used to get webhook URLs.
- log: The logger used to log messages.
Returns:
- A pointer to the initialized StateManager.
func (*StateManager) Send ¶
Send sends a status update to the specified webhook ID.
If the status is the same as the current status in the cache, the status update is not sent and the status is added to the cache.
Parameters:
- ctx: The context.Context used to cancel the operation if needed.
- id: The UUID of the webhook.
- status: The entities.Status to send.
Returns:
- An error if the webhook URL cannot be retrieved from the repository, or if the status update cannot be sent to the webhook.
- nil if the status update was sent successfully or if the status is the same as the current status in the cache.
type WebhookRegistry ¶
type WebhookRegistry interface { // Get retrieves a webhook by its ID. // // Parameters: // - ctx: The context.Context used to cancel the operation if needed. // - id: The UUID of the webhook to retrieve. // // Returns: // - webhookData: The webhook data. // - err: An error if the webhook is not found or if there is an issue retrieving it. Get(ctx context.Context, id uuid.UUID) (webhookData string, err error) // All returns all webhook IDs. // // This method returns all webhook IDs as a slice of UUIDs. All() []uuid.UUID }
WebhookRegistry represents an interface for managing webhooks.
A WebhookRegistry is responsible for retrieving webhooks by their IDs. It provides a Get method for retrieving a webhook by its UUID. The Get method takes a context.Context used to cancel the operation if needed and a UUID representing the ID of the webhook to retrieve. It returns a string representing the webhook data and an error if the webhook is not found or if there is an issue retrieving it.