-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (37 loc) · 1.13 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 (
"encoding/json"
"log"
"net/http"
"server/db"
"server/handlers"
"server/middleware"
"github.com/gorilla/mux"
)
func main() {
// Initialize the database
db.InitDB()
// Set up the router
r := mux.NewRouter()
// WebSocket route
r.HandleFunc("/ws", handlers.WebSocketHandler)
// Drawings route
r.HandleFunc("/drawings", handlers.SaveDrawingHandler).Methods("POST") // this is not being used
r.HandleFunc("/drawings", handlers.GetDrawingsHandler).Methods("GET")
http.HandleFunc("/health", healthCheckHandler)
// Apply CORS middleware
http.Handle("/", middleware.EnableCORS(r))
// Start the server
log.Println("Server started on :8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
// Set the header for JSON response
w.Header().Set("Content-Type", "application/json")
// Respond with a simple JSON object
response := map[string]string{"status": "ok"}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}