gito/services/core/internal/controlplane/router.go
toki e2bc7aa8b6 feat(scaffold): 초기 프로젝트 골격을 구성한다
Gito를 platformless Git control plane으로 시작할 수 있도록 Go core, Flutter control surface, contracts, ops 규칙, 검증 헬퍼를 함께 구성한다.
2026-06-13 08:55:46 +09:00

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)
}