diff --git a/templates/go/http/handle.go b/templates/go/http/handle.go index 5c192d6e..b455d9ae 100644 --- a/templates/go/http/handle.go +++ b/templates/go/http/handle.go @@ -2,12 +2,20 @@ package function import ( "context" + "fmt" "net/http" + "os" ) // Handle an HTTP Request. -func Handle(ctx context.Context, res http.ResponseWriter, req *http.Request) error { +func Handle(ctx context.Context, res http.ResponseWriter, req *http.Request) { + res.Header().Add("Content-Type", "text/plain") - res.Write([]byte("OK\n")) - return nil + res.Header().Add("Content-Length", "3") + res.WriteHeader(200) + + _, err := fmt.Fprintf(res, "OK\n") + if err != nil { + fmt.Fprintf(os.Stderr, "error or response write: %v", err) + } } diff --git a/templates/go/http/handle_test.go b/templates/go/http/handle_test.go index 4b450dab..494f45e6 100644 --- a/templates/go/http/handle_test.go +++ b/templates/go/http/handle_test.go @@ -19,9 +19,10 @@ func TestHandle(t *testing.T) { // Invoke the Handler via a standard Go http.Handler func(w http.ResponseWriter, req *http.Request) { - err = Handle(context.Background(), w, req) + Handle(context.Background(), w, req) }(w, req) res = w.Result() + defer res.Body.Close() // Assert postconditions if err != nil {