Update main.go
Browse files
main.go
CHANGED
|
@@ -43,4 +43,57 @@ func main() {
|
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
-
func
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
+
func handleRoot(w http.ResponseWriter, r *http.Request) {
|
| 47 |
+
w.Header().Set("Content-Type", "application/json")
|
| 48 |
+
response := map[string]string{
|
| 49 |
+
"message": "网络状态监控 API 服务运行中",
|
| 50 |
+
"version": "1.0.0",
|
| 51 |
+
"time": time.Now().Format(time.RFC3339),
|
| 52 |
+
}
|
| 53 |
+
json.NewEncoder(w).Encode(response)
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
func handleHealth(w http.ResponseWriter, r *http.Request) {
|
| 57 |
+
w.Header().Set("Content-Type", "application/json")
|
| 58 |
+
response := HealthResponse{
|
| 59 |
+
Status: "healthy",
|
| 60 |
+
Timestamp: time.Now().Format(time.RFC3339),
|
| 61 |
+
Service: "network-monitor",
|
| 62 |
+
Version: "1.0.0",
|
| 63 |
+
}
|
| 64 |
+
json.NewEncoder(w).Encode(response)
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
func handleNetworkStatus(w http.ResponseWriter, r *http.Request) {
|
| 68 |
+
w.Header().Set("Content-Type", "application/json")
|
| 69 |
+
w.Header().Set("Access-Control-Allow-Origin", "*")
|
| 70 |
+
|
| 71 |
+
status := NetworkStatus{
|
| 72 |
+
Online: true,
|
| 73 |
+
Timestamp: time.Now().Format(time.RFC3339),
|
| 74 |
+
Server: "running",
|
| 75 |
+
Environment: "production",
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
json.NewEncoder(w).Encode(status)
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
func handleServerInfo(w http.ResponseWriter, r *http.Request) {
|
| 82 |
+
w.Header().Set("Content-Type", "application/json")
|
| 83 |
+
w.Header().Set("Access-Control-Allow-Origin", "*")
|
| 84 |
+
|
| 85 |
+
info := map[string]interface{}{
|
| 86 |
+
"server": "Network Monitor API",
|
| 87 |
+
"version": "1.0.0",
|
| 88 |
+
"environment": "production",
|
| 89 |
+
"timestamp": time.Now().Format(time.RFC3339),
|
| 90 |
+
"endpoints": []string{
|
| 91 |
+
"GET /",
|
| 92 |
+
"GET /api/health",
|
| 93 |
+
"GET /api/network-status",
|
| 94 |
+
"GET /api/server-info",
|
| 95 |
+
},
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
json.NewEncoder(w).Encode(info)
|
| 99 |
+
}
|