Gito를 platformless Git control plane으로 시작할 수 있도록 Go core, Flutter control surface, contracts, ops 규칙, 검증 헬퍼를 함께 구성한다.
35 lines
1 KiB
Go
35 lines
1 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"git.toki-labs.com/toki/gito/services/core/internal/config"
|
|
)
|
|
|
|
func NewRouter(cfg config.Config, logger *slog.Logger) http.Handler {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
|
|
writeJSON(w, http.StatusOK, map[string]string{"status": "ok"})
|
|
})
|
|
mux.HandleFunc("/readyz", func(w http.ResponseWriter, _ *http.Request) {
|
|
writeJSON(w, http.StatusOK, map[string]string{
|
|
"status": "ready",
|
|
"env": cfg.AppEnv,
|
|
})
|
|
})
|
|
mux.HandleFunc(cfg.ProtoSocketPath, func(w http.ResponseWriter, r *http.Request) {
|
|
logger.Info("proto-socket endpoint placeholder", "path", r.URL.Path)
|
|
writeJSON(w, http.StatusNotImplemented, map[string]string{
|
|
"error": "proto-socket endpoint is not implemented yet",
|
|
})
|
|
})
|
|
return mux
|
|
}
|
|
|
|
func writeJSON(w http.ResponseWriter, status int, value any) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(status)
|
|
_ = json.NewEncoder(w).Encode(value)
|
|
}
|