mirror of https://github.com/knative/func.git
fix: signature of HTTP go function in template
This commit is contained in:
parent
bcd692be77
commit
bb575b04c0
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue