aboutsummaryrefslogtreecommitdiff
path: root/api/telegram/bot
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-03-03 04:59:34 +0700
committerShulhan <ms@kilabit.info>2024-03-05 14:53:12 +0700
commit2fa7605727e90ca323b7b24168632e485d74c583 (patch)
tree3533df0fc07ef96b1564736926cc3310994be515 /api/telegram/bot
parentb921ebfb3e81b367ff24305eb18c5dd073b38635 (diff)
downloadpakakeh.go-2fa7605727e90ca323b7b24168632e485d74c583.tar.xz
all: comply with linter recommendations #2
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
Diffstat (limited to 'api/telegram/bot')
-rw-r--r--api/telegram/bot/bot.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/api/telegram/bot/bot.go b/api/telegram/bot/bot.go
index 2f237489..7cbbdc0a 100644
--- a/api/telegram/bot/bot.go
+++ b/api/telegram/bot/bot.go
@@ -133,7 +133,7 @@ func New(opts Options) (bot *Bot, err error) {
// DeleteWebhook remove webhook integration if you decide to switch back to
// getUpdates. Returns True on success. Requires no parameters.
func (bot *Bot) DeleteWebhook() (err error) {
- _, resBody, err := bot.client.PostForm(methodDeleteWebhook, nil, nil)
+ _, resBody, err := bot.client.PostForm(methodDeleteWebhook, nil, nil) //nolint: bodyclose
if err != nil {
return fmt.Errorf("DeleteWebhook: %w", err)
}
@@ -151,7 +151,7 @@ func (bot *Bot) DeleteWebhook() (err error) {
// Requires no parameters.
// Returns basic information about the bot in form of a User object.
func (bot *Bot) GetMe() (user *User, err error) {
- _, resBody, err := bot.client.Get(methodGetMe, nil, nil)
+ _, resBody, err := bot.client.Get(methodGetMe, nil, nil) //nolint: bodyclose
if err != nil {
return nil, fmt.Errorf("GetMe: %w", err)
}
@@ -170,7 +170,7 @@ func (bot *Bot) GetMe() (user *User, err error) {
// GetMyCommands get the current list of the bot's commands.
func (bot *Bot) GetMyCommands() (cmds []Command, err error) {
- _, resBody, err := bot.client.Get(methodGetMyCommands, nil, nil)
+ _, resBody, err := bot.client.Get(methodGetMyCommands, nil, nil) //nolint: bodyclose
if err != nil {
return nil, fmt.Errorf("GetMyCommands: %w", err)
}
@@ -191,7 +191,7 @@ func (bot *Bot) GetMyCommands() (cmds []Command, err error) {
// If the bot is using getUpdates, will return an object with the url field
// empty.
func (bot *Bot) GetWebhookInfo() (webhookInfo *WebhookInfo, err error) {
- _, resBody, err := bot.client.Get(methodGetWebhookInfo, nil, nil)
+ _, resBody, err := bot.client.Get(methodGetWebhookInfo, nil, nil) //nolint: bodyclose
if err != nil {
return nil, fmt.Errorf("GetWebhookInfo: %w", err)
}
@@ -219,7 +219,7 @@ func (bot *Bot) SendMessage(parent *Message, parseMode, text string) (
ParseMode: parseMode,
}
- _, resBody, err := bot.client.PostJSON(methodSendMessage, nil, req)
+ _, resBody, err := bot.client.PostJSON(methodSendMessage, nil, req) //nolint: bodyclose
if err != nil {
return nil, fmt.Errorf("SendMessage: %w", err)
}
@@ -253,7 +253,7 @@ func (bot *Bot) SetMyCommands(cmds []Command) (err error) {
bot.commands.Commands = cmds
- _, resBody, err := bot.client.PostJSON(methodSetMyCommands, nil, &bot.commands)
+ _, resBody, err := bot.client.PostJSON(methodSetMyCommands, nil, &bot.commands) //nolint: bodyclose
if err != nil {
return fmt.Errorf("SetMyCommands: %w", err)
}
@@ -318,7 +318,7 @@ func (bot *Bot) setWebhook() (err error) {
var resBody []byte
- _, resBody, err = bot.client.PostFormData(methodSetWebhook, nil, params)
+ _, resBody, err = bot.client.PostFormData(methodSetWebhook, nil, params) //nolint: bodyclose
if err != nil {
return fmt.Errorf(`%s: %w`, logp, err)
}
@@ -402,7 +402,7 @@ func (bot *Bot) createServer() (err error) {
// handleWebhook handle Updates from Webhook.
func (bot *Bot) handleWebhook(epr *http.EndpointRequest) (resBody []byte, err error) {
- update := Update{}
+ var update Update
err = json.Unmarshal(epr.RequestBody, &update)
if err != nil {