Files
vt/fx/echo.go
2026-01-22 17:39:04 +01:00

33 lines
636 B
Go

package fx
import (
"fmt"
"io"
"net/http"
"os"
)
// EchoHandler is an http.Handler that copies its request body
// back to the response.
type EchoHandler struct{}
// NewEchoHandler builds a new EchoHandler.
func NewEchoHandler() *EchoHandler {
return &EchoHandler{}
}
// ServeHTTP handles an HTTP request to the /echo endpoint.
func (*EchoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if _, err := io.Copy(w, r.Body); err != nil {
fmt.Fprintln(os.Stderr, "Failed to handle request:", err)
}
}
func (e *EchoHandler) Handler() http.Handler {
return e
}
func (*EchoHandler) Path() string {
return "/echo"
}