-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
34 lines (28 loc) · 749 Bytes
/
main.go
File metadata and controls
34 lines (28 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/api/:wordToSearch", func(c *gin.Context) {
wordToSearch := c.Param("wordToSearch")
outputJSON := getMeaning(wordToSearch)
c.JSON(http.StatusOK, outputJSON)
})
r.POST("/api/tg", func(c *gin.Context) {
var body Update
err := c.ShouldBindJSON(&body)
if err != nil {
// error handle
}
log.Println(body.Message.Text)
outputJSON := getMeaning(body.Message.Text)
SendTextToTelegramChat(body.Message.Chat.Id, PreprocessingJSONToString(outputJSON))
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
func getMeaning(wordToSearch string) wordMeaning {
return Search(wordToSearch)
}