Commit: Bulk unfinished work
This commit is contained in:
32
fx/echo.go
Normal file
32
fx/echo.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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"
|
||||
}
|
||||
Reference in New Issue
Block a user