-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (39 loc) · 1.32 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
package main
import (
"buildr/src/handlers"
"buildr/src/routes"
"buildr/src/utils"
"fmt"
"net/http"
)
func main() {
// Load Configurations
cfg, err := utils.LoadConfig()
if err != nil {
fmt.Printf("Failed to load config: %v\n", err)
return
}
mux := http.NewServeMux()
// Login / Logout
mux.HandleFunc("/login", routes.Login) // Login route
mux.HandleFunc("/init-user", handlers.InitUser)
mux.HandleFunc("/logout", handlers.LogoutHandler) // Logout process
// Initialize Routes
mux.HandleFunc("/", routes.Index)
mux.HandleFunc("/settings", routes.Settings)
// Function Handlers
mux.HandleFunc("/send-signed-kind1", handlers.SendSignedKind1)
// Serve Web Files
// Serve specific files from the root directory
mux.HandleFunc("/favicon.svg", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "web/favicon.svg")
})
// Serve static files from the /web/static directory at /static/
staticDir := "web/static"
mux.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir(staticDir))))
// Serve CSS files from the /web/style directory at /style/
styleDir := "web/style"
mux.Handle("/style/", http.StripPrefix("/style", http.FileServer(http.Dir(styleDir))))
fmt.Printf("Server is running on http://localhost:%d\n", cfg.Port)
http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), mux)
}