forked from pocket-id/analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (33 loc) · 846 Bytes
/
main.go
File metadata and controls
41 lines (33 loc) · 846 Bytes
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
package main
import (
"log"
"net/http"
"os"
)
func main() {
// Initialize database
db, err := initDB()
if err != nil {
log.Fatal("Failed to initialize database:", err)
}
defer db.Close()
// Set up HTTP handlers
http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
http.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
http.HandleFunc("POST /heartbeat", func(w http.ResponseWriter, r *http.Request) {
HeartbeatHandler(db)(w, r)
})
http.HandleFunc("GET /stats", func(w http.ResponseWriter, r *http.Request) {
StatsHandler(db)(w, r)
})
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Println("Server starting on :" + port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}