-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·71 lines (62 loc) · 1.85 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"github.com/tenderdb/tenderdb/handlers"
"github.com/tenderdb/tenderdb/config"
"github.com/tenderdb/tenderdb/repositories"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"net/http"
"log"
)
func main() {
conf := config.NewConfig()
repo := repositories.NewRepository()
repo.AddUsersDB(conf.UsersDB)
repo.AddCartsDB(conf.CartsDB)
repo.AddMinDB(conf.MinDB)
repo.AddAutocompleteDB(conf.AutocompleteDB)
repo.AddCodesDB(conf.CodesDB)
repo.AddTreeDB(conf.TreeDB)
repo.AddMaxDB(conf.MaxDB)
repo.AddYears(conf.Years)
repo.AddFZs(conf.FZs)
h := handlers.NewHandler(repo)
h.AddNewTemplate(conf.Templates)
h.AddNewSession(conf.Session)
h.AddNewFileServer(conf.Assets)
h.AddNewYandexProvider(conf.YandexID, conf.YandexSecret, conf.YandexRedirect)
h.AddNewGoogleProvider(conf.GoogleID, conf.GoogleSecret, conf.GoogleRedirect)
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Get("/", h.Index)
r.Get("/example", h.Example)
r.Route("/testmode", func (r chi.Router){
r.Use(middleware.BasicAuth("X", map[string]string{"admin":"pass"}))
r.Use(h.CreateTestSession)
r.Get("/", h.RedirectBack)
})
r.Route("/auth/{provider}", func (r chi.Router){
r.Use(h.CheckAuthResponse)
r.Get("/", h.RedirectBack)
})
r.Route("/exit", func (r chi.Router){
r.Use(h.Exit)
r.Get("/", h.RedirectBack)
})
r.Get("/autocomplete", h.Autocomplete)
r.Get("/fetch", h.Fetch)
r.Route("/authorized", func(r chi.Router) {
r.Use(h.CheckAuth)
r.Get("/filter", h.Filter)
r.Get("/download", h.DownloadCsv)
r.Route("/charts", func(r chi.Router) {
r.Get("/", h.ReadCharts)
r.Put("/", h.UpdateChart)
r.Delete("/", h.DeleteChart)
})
})
r.Get("/assets/{}", func(w http.ResponseWriter, req *http.Request){
http.StripPrefix("/assets/", h.FileServer).ServeHTTP(w,req)
})
log.Fatal(http.ListenAndServe(":" + conf.Port, r))
}