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 ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"os"
) )
// Handle an HTTP Request. // 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.Header().Add("Content-Type", "text/plain")
res.Write([]byte("OK\n")) res.Header().Add("Content-Length", "3")
return nil 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 // Invoke the Handler via a standard Go http.Handler
func(w http.ResponseWriter, req *http.Request) { func(w http.ResponseWriter, req *http.Request) {
err = Handle(context.Background(), w, req) Handle(context.Background(), w, req)
}(w, req) }(w, req)
res = w.Result() res = w.Result()
defer res.Body.Close()
// Assert postconditions // Assert postconditions
if err != nil { if err != nil {