-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (31 loc) · 773 Bytes
/
main.go
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
35
36
37
38
39
40
package main
import (
"fmt"
"log"
"net/http"
"github.com/gin-gonic/gin"
"telegram-bot-api/config"
"telegram-bot-api/src/clients"
"telegram-bot-api/src/handlers"
)
func main() {
router := gin.Default()
router.Use(assingCORSconfig())
bot := clients.Init()
handlers.Init(bot)
port := config.Config("PORT")
fmt.Printf("Server listening on port %s...\n", port)
log.Fatal(router.Run(":" + port))
}
func assingCORSconfig() gin.HandlerFunc {
return func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
c.Header("Access-Control-Allow-Headers", "*")
if c.Request.Method == http.MethodOptions {
c.AbortWithStatus(http.StatusOK)
return
}
c.Next()
}
}