feat: complete cmpp platform phases 0-5

This commit is contained in:
hectorzhao
2026-07-01 13:22:04 +08:00
parent 824a8b334f
commit ee926fea04
86 changed files with 10490 additions and 14 deletions
+26
View File
@@ -0,0 +1,26 @@
package health
import (
"encoding/json"
"net/http"
"time"
)
type Status struct {
Status string `json:"status"`
Service string `json:"service"`
Timestamp string `json:"timestamp"`
}
func Handler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(Status{
Status: "ok",
Service: "cmpp-gateway",
Timestamp: time.Now().UTC().Format(time.RFC3339Nano),
})
})
return mux
}
+31
View File
@@ -0,0 +1,31 @@
package health
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestHealthHandler(t *testing.T) {
server := httptest.NewServer(Handler())
defer server.Close()
response, err := http.Get(server.URL + "/health")
if err != nil {
t.Fatalf("get health: %v", err)
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
t.Fatalf("unexpected status: %d", response.StatusCode)
}
var payload Status
if err := json.NewDecoder(response.Body).Decode(&payload); err != nil {
t.Fatalf("decode health payload: %v", err)
}
if payload.Status != "ok" || payload.Service != "cmpp-gateway" {
t.Fatalf("unexpected payload: %+v", payload)
}
}