From 0d7e3db7f846a13b59de9007b3d5cd4bacd7a667 Mon Sep 17 00:00:00 2001 From: Lucas Roesler Date: Sun, 27 Mar 2022 15:29:38 +0200 Subject: [PATCH] feat: upgrade to go 1.18 and support modules via workspaces Update the Go template to use Go 1.18 and workspaces to handle module replacements. Signed-off-by: Lucas Roesler --- template/go/Dockerfile | 6 ++---- template/go/function/go.mod | 3 +++ template/go/go.mod | 4 +--- template/go/go.work | 6 ++++++ 4 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 template/go/function/go.mod create mode 100644 template/go/go.work diff --git a/template/go/Dockerfile b/template/go/Dockerfile index 37078ac4..8410a980 100644 --- a/template/go/Dockerfile +++ b/template/go/Dockerfile @@ -1,5 +1,5 @@ FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.2.0 as watchdog -FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.17-alpine3.15 as builder +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.18-alpine3.15 as builder ARG TARGETPLATFORM ARG BUILDPLATFORM @@ -24,13 +24,11 @@ ENV CGO_ENABLED=0 WORKDIR /go/src/handler COPY . . -# Add user overrides to the root go.mod, which is the only place "replace" can be used -RUN cat function/GO_REPLACE.txt >> ./go.mod || exit 0 - # Run a gofmt and exclude all vendored code. RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; } WORKDIR /go/src/handler/function +RUN go env RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} go test ./... -cover diff --git a/template/go/function/go.mod b/template/go/function/go.mod new file mode 100644 index 00000000..45f94acf --- /dev/null +++ b/template/go/function/go.mod @@ -0,0 +1,3 @@ +module handler/function + +go 1.18 diff --git a/template/go/go.mod b/template/go/go.mod index 64342319..34496254 100644 --- a/template/go/go.mod +++ b/template/go/go.mod @@ -1,5 +1,3 @@ module handler -go 1.16 - -replace handler/function => ./function +go 1.18 diff --git a/template/go/go.work b/template/go/go.work new file mode 100644 index 00000000..8f6f1658 --- /dev/null +++ b/template/go/go.work @@ -0,0 +1,6 @@ +go 1.18 + +use ( + . + ./function +)