-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (36 loc) · 1 KB
/
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
41
42
package main
import (
"log"
"net/http"
"time"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
func main() {
initialize("config.yaml", log.Fatalln)
go runTask()
r := chi.NewRouter()
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
r.Use(middleware.NoCache)
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(middleware.Timeout(time.Minute))
r.Route(config.pathPrefix, func(r chi.Router) {
r.Handle("/", useContext(handleAuth))
r.Handle("/login", useContext(handleLogin))
r.Handle("/callback", useContext(handleCallback))
})
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
})
r.MethodNotAllowed(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusMethodNotAllowed)
})
log.Printf("TelegramAuth is starting for @%v on %v%v",
config.botName, config.listenAddress, config.pathPrefix)
err := http.ListenAndServe(config.listenAddress, r)
if err != nil {
log.Fatalln("fail to start server:", err)
}
}