-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
68 lines (52 loc) · 2.79 KB
/
routes.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
package main
import (
"fmt"
"net/http"
"github.com/Pomog/ForumFFF/internal/config"
"github.com/Pomog/ForumFFF/internal/handler"
)
// routes returns an HTTP handler that routes requests to the appropriate handlers.
func routes(a *config.AppConfig) http.Handler {
mux := http.NewServeMux()
registerStaticHandlers(mux)
// Register handlers for application-specific routes.
mux.HandleFunc("/", handler.Repo.LoginHandler)
mux.HandleFunc("/home", handler.Repo.HomeHandler)
mux.HandleFunc("/theme", handler.Repo.ThemeHandler)
mux.HandleFunc("/registration", handler.Repo.RegisterHandler)
mux.HandleFunc("/error-page", handler.Repo.ErrorPage)
mux.HandleFunc("/contactUs", handler.Repo.ContactUsHandler)
mux.HandleFunc("/forum_rules", handler.Repo.ForumRulesHandler)
mux.HandleFunc("/help", handler.Repo.HelpHandler)
mux.HandleFunc("/privat_policy", handler.Repo.PrivatPolicyHandler)
mux.HandleFunc("/personal_cabinet", handler.Repo.PersonaCabinetHandler)
//handlers to edit delete inidvidual posts
mux.HandleFunc("/edit_post", handler.Repo.EditPostHandler)
mux.HandleFunc("/edit_post_result", handler.Repo.EditPostResultHandler)
mux.HandleFunc("/delete_post_result", handler.Repo.DeletePostHandler)
//handlers to edit delete whole topics
mux.HandleFunc("/edit_topic", handler.Repo.EditTopicHandler)
mux.HandleFunc("/edit_topic_result", handler.Repo.EditTopicResultHandler)
//handlers to get all threads and all posts for user id from personal cabinet
mux.HandleFunc("/personal_cabinet_threads", handler.Repo.GetAllThreadsForUserHandler)
mux.HandleFunc("/personal_cabinet_posts", handler.Repo.GetAllPostsForUserHandler)
mux.HandleFunc("/personal_cabinet_likes", handler.Repo.GetAllLikedPostsByUserIDHandler)
mux.HandleFunc("/personal_cabinet_user_type", handler.Repo.ChangeUserTypeResultHandler) //handler to change user type
mux.HandleFunc("/create_post_result", handler.Repo.CreatePostResultHandler)
mux.HandleFunc("/login-github", handler.Repo.LoginWithGitHubHandler)
mux.HandleFunc("/github-callback", handler.Repo.CallbackGitHubHandler)
mux.HandleFunc("/login-google", handler.Repo.LoginWithGoogleHandler)
mux.HandleFunc("/google-callback", handler.Repo.CallbackGoogleHandler)
mux.HandleFunc("/moder_panel", handler.Repo.ModerPanelHandler)
mux.HandleFunc("/send-pm", handler.Repo.SendPMHandler)
return mux
}
// registerStaticHandlers registers handlers for static content.
func registerStaticHandlers(mux *http.ServeMux) {
//Define a list of static directories (e.g., "css", "logo", "ava", "post_images").
statics := []string{"css", "logo", "ava", "post_images"}
// Register handlers for static content.
for _, static := range statics {
mux.Handle(fmt.Sprintf("/static/%s/", static), http.StripPrefix(fmt.Sprintf("/static/%s/", static), http.FileServer(http.Dir(fmt.Sprintf("static/%s", static)))))
}
}