Skip to content

Commit

Permalink
func-go v1.21.3 - idiomatic handler signatures (#2227)
Browse files Browse the repository at this point in the history
* update go-http templates to match new idiomatic handler

* update embedded templates

* bump func-go dependency

* regenerate templates

* update template deps again

* run embed again

* update test fixtures

* use go1.22 in CI

* setup metallb right after creating k8s cluster

* func-go v1.21.2

* revert static http handler signature update

Since the Pack and S2I builders do not yet use the new func-go
middleware, we are not yet able update the static static handler template.

* func-go v0.21.3

* revert static handler template test

* update embedded template fs

* try go 1.21 throughout

---------

Co-authored-by: Luke Kingland <[email protected]>
  • Loading branch information
dprotaso and lkingland authored Mar 14, 2024
1 parent 09537e3 commit 4d73d8d
Show file tree
Hide file tree
Showing 19 changed files with 12,464 additions and 12,431 deletions.
4 changes: 2 additions & 2 deletions .github/composite/go-setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "Golang setup"
runs:
using: "composite"
steps:
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x
check-latest: true
24,793 changes: 12,407 additions & 12,386 deletions generate/zz_filesystem_generated.go

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions hack/allocate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ main() {
echo "${em}Allocating...${me}"

kubernetes
loadbalancer
( set -o pipefail; (serving && dns && networking) 2>&1 | sed -e 's/^/svr /')&
( set -o pipefail; (eventing && namespace) 2>&1 | sed -e 's/^/evt /')&
( set -o pipefail; registry 2>&1 | sed -e 's/^/reg /') &
Expand Down Expand Up @@ -168,10 +169,7 @@ dns() {
done
}

networking() {
echo "${em}④ Contour Ingress${me}"
echo "Version: ${contour_version}"

loadbalancer() {
echo "Install load balancer."
kubectl apply -f "https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml"
sleep 5
Expand Down Expand Up @@ -200,6 +198,11 @@ metadata:
name: empty
namespace: metallb-system
EOF
}

networking() {
echo "${em}④ Contour Ingress${me}"
echo "Version: ${contour_version}"

echo "Install a properly configured Contour."
kubectl apply -f "https://github.com/knative/net-contour/releases/download/knative-${contour_version}/contour.yaml"
Expand Down
2 changes: 1 addition & 1 deletion pkg/functions/testdata/testClientRunReadiness/f.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func New() *F {
return &F{time.Now()}
}

func (f *F) Handle(_ context.Context, w http.ResponseWriter, r *http.Request) {
func (f *F) Handle(w http.ResponseWriter, r *http.Request) {
fmt.Println("Request received")
fmt.Fprintf(w, "Request received\n")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/functions/testdata/testClientRunTimeout/f.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func New() *F {
return &F{time.Now()}
}

func (f *F) Handle(_ context.Context, w http.ResponseWriter, r *http.Request) {
func (f *F) Handle(w http.ResponseWriter, r *http.Request) {
fmt.Println("Request received")
fmt.Fprintf(w, "Request received\n")
}
Expand Down
2 changes: 1 addition & 1 deletion templates/go/.instanced-cloudevents/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module function

go 1.14
go 1.21

require github.com/cloudevents/sdk-go/v2 v2.13.0 // indirect
3 changes: 1 addition & 2 deletions templates/go/.instanced-http/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package function

import (
"context"
"fmt"
"net/http"
)
Expand All @@ -24,7 +23,7 @@ func New() *MyFunction {
}

// Handle a request using your function instance.
func (f *MyFunction) Handle(ctx context.Context, res http.ResponseWriter, req *http.Request) {
func (f *MyFunction) Handle(res http.ResponseWriter, req *http.Request) {
fmt.Println("Request received")
fmt.Fprintf(res, "Request received\n")
}
Expand Down
2 changes: 1 addition & 1 deletion templates/go/.instanced-http/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module function

go 1.14
go 1.21
2 changes: 1 addition & 1 deletion templates/go/cloudevents/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module function

go 1.14
go 1.21

require github.com/cloudevents/sdk-go/v2 v2.5.0
2 changes: 1 addition & 1 deletion templates/go/http/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module function

go 1.14
go 1.21
32 changes: 9 additions & 23 deletions templates/go/http/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,24 @@ import (
"context"
"fmt"
"net/http"
"strings"
"net/http/httputil"
)

// Handle an HTTP Request.
func Handle(ctx context.Context, res http.ResponseWriter, req *http.Request) {
func Handle(ctx context.Context, w http.ResponseWriter, r *http.Request) {
/*
* YOUR CODE HERE
*
* Try running `go test`. Add more test as you code in `handle_test.go`.
*/

fmt.Println("Received request")
fmt.Println(prettyPrint(req)) // echo to local output
fmt.Fprintf(res, prettyPrint(req)) // echo to caller
}

func prettyPrint(req *http.Request) string {
b := &strings.Builder{}
fmt.Fprintf(b, "%v %v %v %v\n", req.Method, req.URL, req.Proto, req.Host)
for k, vv := range req.Header {
for _, v := range vv {
fmt.Fprintf(b, " %v: %v\n", k, v)
}
dump, err := httputil.DumpRequest(r, true)
if err != nil {
http.Error(w, fmt.Sprint(err), http.StatusInternalServerError)
return
}

if req.Method == "POST" {
req.ParseForm()
fmt.Fprintln(b, "Body:")
for k, v := range req.Form {
fmt.Fprintf(b, " %v: %v\n", k, v)
}
}

return b.String()
fmt.Println("Received request")
fmt.Printf("%q\n", dump)
fmt.Fprintf(w, "%q", dump)
}
4 changes: 2 additions & 2 deletions templates/go/scaffolding/instanced-cloudevents/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module s

replace f => ./f

go 1.19
go 1.21

require (
f v0.0.0-00010101000000-000000000000
knative.dev/func-go v0.20.0
knative.dev/func-go v0.21.3
)

require (
Expand Down
6 changes: 6 additions & 0 deletions templates/go/scaffolding/instanced-cloudevents/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@ knative.dev/func-go v0.19.0 h1:EYmc3L8eh48YJf79d8B/Y/KnWRPyRzVXUPBLpFn2boU=
knative.dev/func-go v0.19.0/go.mod h1:+Og4a5pqW5WfBrv8Xf0jcTx5s+LiUpzcXyWBIuwKz30=
knative.dev/func-go v0.20.0 h1:i8sp5NwCQSKWa73wDbuZWcGwdBkMG7vnMSqcUVWtT+E=
knative.dev/func-go v0.20.0/go.mod h1:+Og4a5pqW5WfBrv8Xf0jcTx5s+LiUpzcXyWBIuwKz30=
knative.dev/func-go v0.21.1 h1:qKrs9eLKRnJCJiPAp3ei7yuGGzGXODhiLP1KaO/ozyU=
knative.dev/func-go v0.21.1/go.mod h1:F+y4XuLwg27Rwn3w9BFNKf6HLkPPbDlkq0aXnGfkcvU=
knative.dev/func-go v0.21.2 h1:euhnyAxOfrQGeKj4RU80X2NNNsI+qiMx6PMwg/MeT5s=
knative.dev/func-go v0.21.2/go.mod h1:YAUlPi4bY5OQb7n9424zm9GtRigOQ1/IBtqkLqC29Dw=
knative.dev/func-go v0.21.3 h1:gmA0t1oyP088KPBidKnYiP1xQvmtPRp3phJ4McJazsc=
knative.dev/func-go v0.21.3/go.mod h1:YAUlPi4bY5OQb7n9424zm9GtRigOQ1/IBtqkLqC29Dw=
4 changes: 2 additions & 2 deletions templates/go/scaffolding/instanced-http/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module s

replace f => ./f

go 1.19
go 1.21

require (
f v0.0.0-00010101000000-000000000000
knative.dev/func-go v0.20.0
knative.dev/func-go v0.21.3
)

require (
Expand Down
6 changes: 6 additions & 0 deletions templates/go/scaffolding/instanced-http/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ knative.dev/func-go v0.19.0 h1:EYmc3L8eh48YJf79d8B/Y/KnWRPyRzVXUPBLpFn2boU=
knative.dev/func-go v0.19.0/go.mod h1:+Og4a5pqW5WfBrv8Xf0jcTx5s+LiUpzcXyWBIuwKz30=
knative.dev/func-go v0.20.0 h1:i8sp5NwCQSKWa73wDbuZWcGwdBkMG7vnMSqcUVWtT+E=
knative.dev/func-go v0.20.0/go.mod h1:+Og4a5pqW5WfBrv8Xf0jcTx5s+LiUpzcXyWBIuwKz30=
knative.dev/func-go v0.21.1 h1:qKrs9eLKRnJCJiPAp3ei7yuGGzGXODhiLP1KaO/ozyU=
knative.dev/func-go v0.21.1/go.mod h1:F+y4XuLwg27Rwn3w9BFNKf6HLkPPbDlkq0aXnGfkcvU=
knative.dev/func-go v0.21.2 h1:euhnyAxOfrQGeKj4RU80X2NNNsI+qiMx6PMwg/MeT5s=
knative.dev/func-go v0.21.2/go.mod h1:YAUlPi4bY5OQb7n9424zm9GtRigOQ1/IBtqkLqC29Dw=
knative.dev/func-go v0.21.3 h1:gmA0t1oyP088KPBidKnYiP1xQvmtPRp3phJ4McJazsc=
knative.dev/func-go v0.21.3/go.mod h1:YAUlPi4bY5OQb7n9424zm9GtRigOQ1/IBtqkLqC29Dw=
4 changes: 2 additions & 2 deletions templates/go/scaffolding/static-cloudevents/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module s

replace f => ./f

go 1.19
go 1.21

require (
f v0.0.0-00010101000000-000000000000
knative.dev/func-go v0.20.0
knative.dev/func-go v0.21.3
)

require (
Expand Down
6 changes: 6 additions & 0 deletions templates/go/scaffolding/static-cloudevents/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ knative.dev/func-go v0.19.0 h1:EYmc3L8eh48YJf79d8B/Y/KnWRPyRzVXUPBLpFn2boU=
knative.dev/func-go v0.19.0/go.mod h1:+Og4a5pqW5WfBrv8Xf0jcTx5s+LiUpzcXyWBIuwKz30=
knative.dev/func-go v0.20.0 h1:i8sp5NwCQSKWa73wDbuZWcGwdBkMG7vnMSqcUVWtT+E=
knative.dev/func-go v0.20.0/go.mod h1:+Og4a5pqW5WfBrv8Xf0jcTx5s+LiUpzcXyWBIuwKz30=
knative.dev/func-go v0.21.1 h1:qKrs9eLKRnJCJiPAp3ei7yuGGzGXODhiLP1KaO/ozyU=
knative.dev/func-go v0.21.1/go.mod h1:F+y4XuLwg27Rwn3w9BFNKf6HLkPPbDlkq0aXnGfkcvU=
knative.dev/func-go v0.21.2 h1:euhnyAxOfrQGeKj4RU80X2NNNsI+qiMx6PMwg/MeT5s=
knative.dev/func-go v0.21.2/go.mod h1:YAUlPi4bY5OQb7n9424zm9GtRigOQ1/IBtqkLqC29Dw=
knative.dev/func-go v0.21.3 h1:gmA0t1oyP088KPBidKnYiP1xQvmtPRp3phJ4McJazsc=
knative.dev/func-go v0.21.3/go.mod h1:YAUlPi4bY5OQb7n9424zm9GtRigOQ1/IBtqkLqC29Dw=
4 changes: 2 additions & 2 deletions templates/go/scaffolding/static-http/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module s

replace f => ./f

go 1.19
go 1.21

require (
f v0.0.0-00010101000000-000000000000
knative.dev/func-go v0.20.0
knative.dev/func-go v0.21.3
)

require (
Expand Down
6 changes: 6 additions & 0 deletions templates/go/scaffolding/static-http/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ knative.dev/func-go v0.19.0 h1:EYmc3L8eh48YJf79d8B/Y/KnWRPyRzVXUPBLpFn2boU=
knative.dev/func-go v0.19.0/go.mod h1:+Og4a5pqW5WfBrv8Xf0jcTx5s+LiUpzcXyWBIuwKz30=
knative.dev/func-go v0.20.0 h1:i8sp5NwCQSKWa73wDbuZWcGwdBkMG7vnMSqcUVWtT+E=
knative.dev/func-go v0.20.0/go.mod h1:+Og4a5pqW5WfBrv8Xf0jcTx5s+LiUpzcXyWBIuwKz30=
knative.dev/func-go v0.21.1 h1:qKrs9eLKRnJCJiPAp3ei7yuGGzGXODhiLP1KaO/ozyU=
knative.dev/func-go v0.21.1/go.mod h1:F+y4XuLwg27Rwn3w9BFNKf6HLkPPbDlkq0aXnGfkcvU=
knative.dev/func-go v0.21.2 h1:euhnyAxOfrQGeKj4RU80X2NNNsI+qiMx6PMwg/MeT5s=
knative.dev/func-go v0.21.2/go.mod h1:YAUlPi4bY5OQb7n9424zm9GtRigOQ1/IBtqkLqC29Dw=
knative.dev/func-go v0.21.3 h1:gmA0t1oyP088KPBidKnYiP1xQvmtPRp3phJ4McJazsc=
knative.dev/func-go v0.21.3/go.mod h1:YAUlPi4bY5OQb7n9424zm9GtRigOQ1/IBtqkLqC29Dw=

0 comments on commit 4d73d8d

Please sign in to comment.