package router import ( "net/http" "aws-sts-mock/internal/handler" ) // Router handles HTTP routing type Router struct { s3Handler *handler.S3Handler stsHandler *handler.STSHandler healthHandler *handler.HealthHandler sigv4Middleware func(http.HandlerFunc) http.HandlerFunc } // New creates a new router func New( s3Handler *handler.S3Handler, stsHandler *handler.STSHandler, healthHandler *handler.HealthHandler, sigv4Middleware func(http.HandlerFunc) http.HandlerFunc, ) http.Handler { r := &Router{ s3Handler: s3Handler, stsHandler: stsHandler, healthHandler: healthHandler, sigv4Middleware: sigv4Middleware, } mux := http.NewServeMux() // Health check endpoint - without SigV4 validation mux.HandleFunc("/health", r.healthHandler.Handle) // Main handler with SigV4 validation mux.HandleFunc("/", r.sigv4Middleware(r.handleRequest)) return mux } // handleRequest routes requests to appropriate handlers func (r *Router) handleRequest(w http.ResponseWriter, req *http.Request) { // STS requests have Action parameter if req.Method == "POST" && req.FormValue("Action") != "" { r.stsHandler.Handle(w, req) return } // Otherwise, treat as S3 request r.s3Handler.Handle(w, req) }