1- package mockapp
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- } return "1.0.0" } return v if v := os .Getenv ("APP_VERSION" ); v != "" {func getVersion () string {} fmt .Fprintf (w , "Uptime: %s\n " , time .Since (startTime )) fmt .Fprintf (w , "Mock App v%s\n " , getVersion ()) w .Header ().Set ("Content-Type" , "text/plain" )func rootHandler (w http .ResponseWriter , r * http .Request ) {} fmt .Fprint (w , "ready" ) w .WriteHeader (http .StatusOK )func readyHandler (w http.ResponseWriter , r * http.Request ) {} json .NewEncoder (w ).Encode (response ) w .Header ().Set ("Content-Type" , "application/json" ) } Uptime: time .Since (startTime ).String (), Version : getVersion (), Timestamp : time .Now ().UTC ().Format (time .RFC3339 ), Status : "healthy" , response := HealthResponse {func healthHandler (w http.ResponseWriter , r * http.Request ) {} } log .Fatalf ("Server failed: %v" , err ) if err := http .ListenAndServe (":" + port , nil ); err != nil { log .Printf ("Mock app starting on port %s" , port ) http .HandleFunc ("/" , rootHandler ) http .HandleFunc ("/ready" , readyHandler ) http .HandleFunc ("/health" , healthHandler ) } port = "8080" if port == "" { port := os.Getenv ("PORT" )func main () {var startTime = time .Now ()} Uptime string `json:"uptime"` Version string `json:"version"` Timestamp string `json:"timestamp"` Status string `json:"status"` type HealthResponse struct {// HealthResponse represents the health check response) "time" "os" "net/http" "log" "fmt" "encoding/json"import (package main
1+ package main
2+
3+ import (
4+ "encoding/json"
5+ "fmt"
6+ "log"
7+ "net/http"
8+ "os"
9+ "time"
10+ )
11+
12+ // HealthResponse represents the health check response
13+ type HealthResponse struct {
14+ Status string `json:"status"`
15+ Timestamp string `json:"timestamp"`
16+ Version string `json:"version"`
17+ Uptime string `json:"uptime"`
18+ }
19+
20+ var startTime = time .Now ()
21+
22+ func main () {
23+ port := os .Getenv ("PORT" )
24+ if port == "" {
25+ port = "8080"
26+ }
27+
28+ http .HandleFunc ("/health" , healthHandler )
29+ http .HandleFunc ("/ready" , readyHandler )
30+ http .HandleFunc ("/" , rootHandler )
31+
32+ log .Printf ("Mock app starting on port %s" , port )
33+ if err := http .ListenAndServe (":" + port , nil ); err != nil {
34+ log .Fatalf ("Server failed: %v" , err )
35+ }
36+ }
37+
38+ func healthHandler (w http.ResponseWriter , r * http.Request ) {
39+ response := HealthResponse {
40+ Status : "healthy" ,
41+ Timestamp : time .Now ().UTC ().Format (time .RFC3339 ),
42+ Version : getVersion (),
43+ Uptime : time .Since (startTime ).String (),
44+ }
45+ w .Header ().Set ("Content-Type" , "application/json" )
46+ json .NewEncoder (w ).Encode (response )
47+ }
48+
49+ func readyHandler (w http.ResponseWriter , r * http.Request ) {
50+ w .WriteHeader (http .StatusOK )
51+ fmt .Fprint (w , "ready" )
52+ }
53+
54+ func rootHandler (w http.ResponseWriter , r * http.Request ) {
55+ w .Header ().Set ("Content-Type" , "text/plain" )
56+ fmt .Fprintf (w , "Mock App v%s\n " , getVersion ())
57+ fmt .Fprintf (w , "Uptime: %s\n " , time .Since (startTime ))
58+ }
59+
60+ func getVersion () string {
61+ if v := os .Getenv ("APP_VERSION" ); v != "" {
62+ return v
63+ }
64+ return "1.0.0"
65+ }
0 commit comments