fix: signature of HTTP go function in template

This commit is contained in:
Matej Vasek 2020-09-09 15:27:38 +02:00 committed by GitHub
parent bcd692be77
commit bb575b04c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -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)
}
}

View File

@ -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 {