Skip to content

Commit

Permalink
Documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorunic committed Oct 10, 2023
1 parent ef56bbf commit 4d3caeb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 31 deletions.
33 changes: 10 additions & 23 deletions messenger/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,17 @@ var (
ErrCalendarNotFound = errors.New("unable to find Google Calendar ID")
)

// Calendar is a function that processes events from a channel and inserts them into a Google Calendar.
// Calendar is a function that processes messages from a channel and creates events in Google Calendar.
//
// It takes in the following parameters:
// - ctx: the context.Context object for handling timeouts and cancellations.
// - ch: a channel of interface{} that contains the events to be processed.
// - name: the name of the Google Calendar.
// - tokFile: the path to the token file.
// - credFile: the path to the credentials file.
// - retries: the number of retry attempts for inserting a Google Calendar event.
// It takes the following parameters:
// - ctx: the context.Context object for managing the execution of the function
// - ch: a channel for receiving messages
// - name: the name of the calendar
// - tokFile: the path to the token file
// - credFile: the path to the credential file
// - retries: the number of retry attempts for inserting a Google Calendar event
//
// It returns an error if any of the following occurs:
// - Unable to read the credentials file.
// - Unable to parse the credentials file.
// - Unable to initialize Google Calendar OAuth.
// - Unable to initialize Google Calendar client.
// - Unable to find the Google Calendar ID for the specified calendar.
// - Unable to insert the Google Calendar event.
//
// The function reads the credentials file and configures the Google API client using the credentials.
// It then initializes the Google Calendar client and retrieves the Google Calendar ID for the specified calendar.
// Next, it processes the events received from the channel, formats the event description, and creates a new all-day event in the Google Calendar.
// Finally, it retries and attempts to insert the event into the Google Calendar, with a delay between each attempt.
//
// The function returns nil if all events are successfully processed and inserted into the Google Calendar.
// It returns an error indicating any issues encountered during the execution of the function.
func Calendar(ctx context.Context, ch <-chan interface{}, name, tokFile, credFile string, retries uint) error {
srv, calID, err := initCalendar(ctx, credFile, tokFile, name)
if err != nil {
Expand Down Expand Up @@ -133,7 +120,7 @@ func Calendar(ctx context.Context, ch <-chan interface{}, name, tokFile, credFil
}
}

return nil
return err
}

// initCalendar initializes a Google Calendar service and retrieves the calendar ID.
Expand Down
10 changes: 8 additions & 2 deletions messenger/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ var (
ErrDiscordSendingMessage = errors.New("error sending Discord message")
)

// Discord messenger processes events from a channel and attempts to communicate to one or more UserIDs, optionally
// returning an error.
// Discord sends messages through the Discord API to the specified user IDs.
//
// ctx: The context.Context that can be used to cancel the operation.
// ch: The channel from which to receive messages.
// token: The Discord API token.
// userIDs: The list of user IDs to send the messages to.
// retries: The number of attempts to send the message before giving up.
// Returns an error if there was a problem sending the message.
func Discord(ctx context.Context, ch <-chan interface{}, token string, userIDs []string, retries uint) error {
if token == "" {
return fmt.Errorf("%w", ErrDiscordEmptyAPIKey)
Expand Down
17 changes: 15 additions & 2 deletions messenger/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,21 @@ var (
ErrMailInvalidPort = errors.New("invalid or missing SMTP port, will try with default 465/tcp")
)

// Mail messenger processes events from a channel and attempts to send emails to one or more recipients,
// optionally returning an error.
// Mail sends a message through the mail service.
//
// The function takes the following parameters:
// - ctx: the context.Context object for cancellation and timeouts.
// - ch: a channel from which messages are received.
// - server: the address of the mail server.
// - port: the port number for the mail server.
// - username: the username for authentication.
// - password: the password for authentication.
// - from: the email address of the sender.
// - subject: the subject of the email.
// - to: a slice of email addresses of the recipients.
// - retries: the number of retry attempts to send the message.
//
// The function returns an error.
func Mail(ctx context.Context, ch <-chan interface{}, server, port, username, password, from, subject string, to []string, retries uint) error {
logger.Debug().Msg("Sending message through mail service")

Expand Down
10 changes: 8 additions & 2 deletions messenger/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ var (
ErrSlackSendingMessage = errors.New("error sending Slack message")
)

// Slack messenger processes events from a channel and attempts to communicate to one or more ChatIDs, optionally
// returning an error.
// Slack sends messages through the Slack API.
//
// ctx: the context in which the function is executed.
// ch: the channel from which messages are received.
// token: the Slack API key.
// chatIDs: the IDs of the recipients.
// retries: the number of retries in case of failure.
// error: an error if there was a problem sending the message.
func Slack(ctx context.Context, ch <-chan interface{}, token string, chatIDs []string, retries uint) error {
if token == "" {
return fmt.Errorf("%w", ErrSlackEmptyAPIKey)
Expand Down
12 changes: 10 additions & 2 deletions messenger/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ var (
ErrTelegramSendingMessage = errors.New("error sending Telegram message")
)

// Telegram messenger processes events from a channel and attempts to communicate to one or more ChatIDs, optionally
// returning an error.
// Telegram sends messages through the Telegram API.
//
// It takes the following parameters:
// - ctx: the context.Context object for handling deadlines and cancellations.
// - ch: a channel for receiving messages to be sent.
// - apiKey: the API key for accessing the Telegram API.
// - chatIDs: a slice of strings containing the IDs of the chat recipients.
// - retries: the number of times to retry sending a message in case of failure.
//
// It returns an error indicating any failures that occurred during the process.
func Telegram(ctx context.Context, ch <-chan interface{}, apiKey string, chatIDs []string, retries uint) error {
if apiKey == "" {
return fmt.Errorf("%w", ErrTelegramEmptyAPIKey)
Expand Down

0 comments on commit 4d3caeb

Please sign in to comment.