go
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"sync/atomic"
"time"
)
var requestCount atomic.Int64
type Response struct {
Message string `json:"message"`
Count int64 `json:"count"`
Timestamp string `json:"timestamp"`
}
func handler(w http.ResponseWriter, r *http.Request) {
count := requestCount.Add(1)
resp := Response{
Message: fmt.Sprintf("Hello from Go! Path: %s", r.URL.Path),
Count: count,
Timestamp: time.Now().UTC().Format(time.RFC3339),
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(resp)
}
func main() {
http.HandleFunc("/", handler)
log.Println("Server starting on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}