aboutsummaryrefslogtreecommitdiff
path: root/api/telegram
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-09-14 00:59:40 +0700
committerShulhan <ms@kilabit.info>2023-09-14 00:59:40 +0700
commitb89afa24feaee375e914a69b23c2036733991f3e (patch)
treefd2c0270a7d7ad644526b77cba409c3956de4820 /api/telegram
parenta352f66260b7172e9553351d44d67c54d48efe7a (diff)
downloadpakakeh.go-b89afa24feaee375e914a69b23c2036733991f3e.tar.xz
all: fix variable shadowing as reported by shadow tool
The shadow tool [1] report a variable where its name is declared twice or more, in different scope. [1] https://pkg.go.dev/golang.org/x/tools@v0.13.0/go/analysis/passes/shadow
Diffstat (limited to 'api/telegram')
-rw-r--r--api/telegram/bot/bot.go28
1 files changed, 17 insertions, 11 deletions
diff --git a/api/telegram/bot/bot.go b/api/telegram/bot/bot.go
index 6461ae23..1e5d899f 100644
--- a/api/telegram/bot/bot.go
+++ b/api/telegram/bot/bot.go
@@ -11,6 +11,7 @@ import (
"fmt"
"log"
stdhttp "net/http"
+ "path"
"strconv"
"github.com/shuLhan/share/lib/errors"
@@ -292,39 +293,44 @@ func (bot *Bot) Stop() (err error) {
}
func (bot *Bot) setWebhook() (err error) {
- params := make(map[string][]byte)
-
- webhookURL := bot.opts.Webhook.URL + "/" + bot.opts.Token
+ var (
+ logp = `setWebhook`
+ params = make(map[string][]byte)
+ webhookURL = path.Join(bot.opts.Webhook.URL, bot.opts.Token)
+ )
params[paramNameURL] = []byte(webhookURL)
if len(bot.opts.Webhook.Certificate) > 0 {
params[paramNameCertificate] = bot.opts.Webhook.Certificate
}
if bot.opts.Webhook.MaxConnections > 0 {
- str := strconv.Itoa(bot.opts.Webhook.MaxConnections)
+ var str = strconv.Itoa(bot.opts.Webhook.MaxConnections)
params[paramNameMaxConnections] = []byte(str)
}
if len(bot.opts.Webhook.AllowedUpdates) > 0 {
- allowedUpdates, err := json.Marshal(&bot.opts.Webhook.AllowedUpdates)
+ var allowedUpdates []byte
+ allowedUpdates, err = json.Marshal(&bot.opts.Webhook.AllowedUpdates)
if err != nil {
- return fmt.Errorf("setWebhook: %w", err)
+ return fmt.Errorf(`%s: %w`, logp, err)
}
params[paramNameAllowedUpdates] = allowedUpdates
}
- _, resBody, err := bot.client.PostFormData(methodSetWebhook, nil, params)
+ var resBody []byte
+
+ _, resBody, err = bot.client.PostFormData(methodSetWebhook, nil, params)
if err != nil {
- return fmt.Errorf("setWebhook: %w", err)
+ return fmt.Errorf(`%s: %w`, logp, err)
}
- res := &response{}
+ var res = &response{}
err = json.Unmarshal(resBody, res)
if err != nil {
- return fmt.Errorf("setWebhook: %w", err)
+ return fmt.Errorf(`%s: %w`, logp, err)
}
- fmt.Printf("setWebhook: response: %+v\n", res)
+ fmt.Printf("%s: response: %+v\n", logp, res)
return nil
}