Refactored code and added logging

This commit is contained in:
Artyom Belousov 2019-11-03 12:16:45 +03:00
parent 8830920900
commit 221ab214cc
11 changed files with 51 additions and 44 deletions

View file

@ -1,6 +1,7 @@
package vk
import (
"log"
"math/rand"
"net/http"
"net/url"
@ -8,17 +9,20 @@ import (
"strings"
)
const VKURL = "https://api.vk.com/method/messages.send"
const SendMessageUrl = "https://api.vk.com/method/messages.send"
func Message(userId int64, message string) {
randomId := rand.Int31()
params := []string{
"access_token=" + TOKEN,
"access_token=" + Token,
"peer_id=" + strconv.FormatInt(userId, 10),
"message=" + url.QueryEscape(message),
"v=5.95",
"random_id=" + strconv.FormatInt(int64(randomId), 10),
}
paramString := strings.Join(params, "&")
http.Get(VKURL + "?" + paramString)
resp, err := http.Get(SendMessageUrl + "?" + paramString)
if err != nil || resp.StatusCode != http.StatusOK {
log.Print("Could not send message\n user: %lld", userId)
}
}