Skip to content

Commit

Permalink
feat: upgrade to go 1.18 and support modules via workspaces
Browse files Browse the repository at this point in the history
Update the Go template to use Go 1.18 and workspaces to handle module
replacements.

Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler authored and alexellis committed Apr 13, 2022
1 parent 7fdbc41 commit 0d7e3db
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 2 additions & 4 deletions template/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions template/go/function/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module handler/function

go 1.18
4 changes: 1 addition & 3 deletions template/go/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module handler

go 1.16

replace handler/function => ./function
go 1.18
6 changes: 6 additions & 0 deletions template/go/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.18

use (
.
./function
)

0 comments on commit 0d7e3db

Please sign in to comment.