hatch-surf/cmd/hatch/main.go
CTO 90c3f6285d feat: mock endpoint — configure response per endpoint
- Add mock_status, mock_headers, mock_body columns to endpoints schema
- Add MockConfig struct and UpsertMock to Repository interface
- Implement UpsertMock in sqliteRepo (INSERT ON CONFLICT UPDATE)
- Update GetEndpoint to return mock configuration when present
- Add PUT /e/{endpoint_id}/mock handler with JSON body {status, headers, body}
- Add catch-all /{endpoint_id} handler returning mock or default 200
- Header sanitization: only allow Content-Type, Cache-Control, X-*
- Wire handler into cmd/hatch main with SQLite store
- Fix Dockerfile: COPY go.sum for reproducible builds
- Tests: store mock CRUD, handler mock config + header sanitization

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-22 14:32:53 +02:00

34 lines
832 B
Go

package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/elfoundation/hatch/internal/handler"
"github.com/elfoundation/hatch/internal/store"
)
func main() {
port := os.Getenv("PORT")
if port == "" { port = "8080" }
dbPath := os.Getenv("HATCH_DB_PATH")
repo, err := store.Open(dbPath)
if err != nil { log.Fatalf("hatch: open store: %v", err) }
defer repo.Close()
h := handler.New(repo)
mux := http.NewServeMux()
mux.HandleFunc("GET /healthz", healthz)
h.RegisterRoutes(mux)
addr := fmt.Sprintf(":%s", port)
log.Printf("hatch starting on %s", addr)
if err := http.ListenAndServe(addr, mux); err != nil { log.Fatalf("hatch server error: %v", err) }
}
func healthz(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "ok")
}