Documentation ¶
Index ¶
- Constants
- Variables
- func Calendar(ctx context.Context, ch <-chan interface{}, name, tokFile string, retries uint) error
- func Discord(ctx context.Context, ch <-chan interface{}, token string, userIDs []string, ...) error
- func InitCalendar(ctx context.Context, tokFile string, name string) (*calendar.Service, string, error)
- func Mail(ctx context.Context, ch <-chan interface{}, ...) error
- func Slack(ctx context.Context, ch <-chan interface{}, token string, chatIDs []string, ...) error
- func Telegram(ctx context.Context, ch <-chan interface{}, apiKey string, chatIDs []string, ...) error
Constants ¶
const ( CalendarAPILimit = 5 // 5 req/s per user CalendarWindow = 1 * time.Second CalendarMinDelay = CalendarWindow / CalendarAPILimit CalendarMaxResults = 100 CalendarCredentials = "assets/calendar_credentials.json" // embedded Google Calendar credentials file )
const ( DiscordAPILimit = 50 // 50 API req/s per user/IP DiscordWindow = 1 * time.Second DiscordMinDelay = DiscordWindow / DiscordAPILimit )
const ( MailSendLimit = 20 // 20 emails per 1 hour MailWindow = 1 * time.Hour MailMinDelay = MailWindow / MailSendLimit MailSubject = "Nova ocjena iz e-Dnevnika" )
const ( SlackAPILImit = 1 // typically 1 req/s per user SlackWindow = 1 * time.Second SlackMinDelay = SlackWindow / SlackAPILImit )
const ( TelegramAPILimit = 30 // 30 API req/s per user TelegramWindow = 1 * time.Second TelegramMinDelay = TelegramWindow / TelegramAPILimit )
Variables ¶
var ( ErrCalendarReadingCreds = errors.New("unable to read credentials file") ErrCalendarParsingCreds = errors.New("unable to parse credentials file") ErrCalendarNotFound = errors.New("unable to find Google Calendar ID") )
var ( ErrDiscordEmptyAPIKey = errors.New("empty Discord API key") ErrDiscordEmptyUserIDs = errors.New("empty list of Discord User IDs") ErrDiscordCreatingSession = errors.New("error creating Discord session") ErrDiscordCreatingChannel = errors.New("error creating Discord channel") ErrDiscordSendingMessage = errors.New("error sending Discord message") )
var ( ErrMailSendingMessage = errors.New("error sending mail message") ErrMailInvalidPort = errors.New("invalid or missing SMTP port, will try with default 587/tcp") )
Functions ¶
func Calendar ¶ added in v0.10.0
Calendar is a function that processes messages from a channel and creates events in Google Calendar.
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 - retries: the number of retry attempts for inserting a Google Calendar event
It returns an error indicating any issues encountered during the execution of the function.
func Discord ¶
func Discord(ctx context.Context, ch <-chan interface{}, token string, userIDs []string, retries uint) 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 InitCalendar ¶ added in v0.14.0
func InitCalendar(ctx context.Context, tokFile string, name string) (*calendar.Service, string, error)
InitCalendar initializes a Google Calendar service and retrieves the calendar ID.
ctx: The context.Context for the function. tokFile: The path to the token file. name: The name of the calendar. returns: - *calendar.Service: A pointer to the calendar.Service. - string: The calendar ID. - error: Any error that occurred during initialization.
func Mail ¶
func Mail(ctx context.Context, ch <-chan interface{}, server, port, username, password, from, subject string, to []string, retries uint) 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 Slack ¶
func Slack(ctx context.Context, ch <-chan interface{}, token string, chatIDs []string, retries uint) 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 Telegram ¶
func Telegram(ctx context.Context, ch <-chan interface{}, apiKey string, chatIDs []string, retries uint) 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.
Types ¶
This section is empty.