-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
33 lines (27 loc) · 698 Bytes
/
main.go
File metadata and controls
33 lines (27 loc) · 698 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
)
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
response := map[string]string{
"status": "healthy",
"message": "API is up and running",
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{"status": "%s", "message": "%s"}`, response["status"], response["message"])
}
func main() {
router := mux.NewRouter()
router.HandleFunc("/health", healthCheckHandler).Methods("GET")
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Printf("Server starting on port %s", port)
log.Fatal(http.ListenAndServe(":"+port, router))
}