Fixed memory leak and made response instant
This commit is contained in:
parent
3ee53b7ad1
commit
c59d47326d
3 changed files with 12 additions and 4 deletions
|
|
@ -23,13 +23,14 @@ func GetOriginalName(name string) string {
|
|||
for i := range langs {
|
||||
go getOriginalNameFromLang(name, langs[i], channel)
|
||||
}
|
||||
var res string
|
||||
for i := 0; i < len(langs); i++ {
|
||||
name := <-channel
|
||||
if name != "" {
|
||||
return name
|
||||
res = name
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return res
|
||||
}
|
||||
|
||||
func getOriginalNameFromLang(name, lang string, channel chan string) {
|
||||
|
|
|
|||
7
main.go
7
main.go
|
|
@ -4,10 +4,17 @@ import (
|
|||
"github.com/flygrounder/mtg-price-vk/vk"
|
||||
"github.com/gin-gonic/gin"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
go (func() {
|
||||
for {
|
||||
time.Sleep(5 * time.Second)
|
||||
println(runtime.NumGoroutine())
|
||||
}
|
||||
})()
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
r := gin.Default()
|
||||
r.POST("callback/message", vk.HandleMessage)
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ func HandleMessage(c *gin.Context) {
|
|||
case "confirmation":
|
||||
handleConfirmation(c, &req)
|
||||
case "message_new":
|
||||
handleSearch(c, &req)
|
||||
go handleSearch(c, &req)
|
||||
c.String(http.StatusOK, "ok")
|
||||
}
|
||||
}
|
||||
|
||||
func handleSearch(c *gin.Context, req *MessageRequest) {
|
||||
defer c.String(http.StatusOK, "ok")
|
||||
cardName, err := getCardNameByCommand(req.Object.Body)
|
||||
if err != nil {
|
||||
Message(req.Object.UserId, "Некорректная команда")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue