-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (33 loc) · 1.24 KB
/
Copy pathmain.go
File metadata and controls
40 lines (33 loc) · 1.24 KB
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 (
"log"
"net/http"
"tkgm-proxy/internal"
)
func main() {
cfg := internal.LoadConfig()
repo, err := internal.NewSQLiteRepository(cfg.DbPath)
if err != nil {
log.Fatalf("Veritabanı hatası: %v", err)
}
defer repo.Close()
proxyServ := internal.NewProxyService(cfg.HGM_API_KEY, cfg.TkgmCacheMinutes, cfg.HgmCacheSeconds)
h := internal.NewHandler(cfg, repo, proxyServ)
mainMux := http.NewServeMux()
mainMux.HandleFunc("/api/login", h.Login)
mainMux.HandleFunc("/api/check-auth", h.CheckAuth)
mainMux.HandleFunc("/login", h.GetLoginPage)
staticFS := http.FileServer(http.Dir("web/static"))
mainMux.Handle("/static/", http.StripPrefix("/static/", staticFS))
protectedMux := http.NewServeMux()
protectedMux.HandleFunc("/", h.GetIndexPage)
protectedMux.HandleFunc("/notes", h.GetNotesPage)
protectedMux.HandleFunc("/api/notes", h.GetNotes)
protectedMux.HandleFunc("/api/notes/save", h.SaveNote)
protectedMux.HandleFunc("/api/notes/delete", h.DeleteNote)
protectedMux.HandleFunc("/api/proxy/", h.ProxyTKGM)
protectedMux.HandleFunc("/api/hgm/orto/", h.ProxyHGM)
protectedMux.HandleFunc("/api/logout", h.Logout)
mainMux.Handle("/", h.AuthMiddleware(protectedMux))
log.Fatal(http.ListenAndServe(":"+cfg.Port, mainMux))
}