I think your issue here is because in your
override-build snippet you have this:
go build -mod=vendor -ldflags="-s -w -X main.GitSHA=$(git rev-parse --short HEAD) -X main.BuildDate=$(date +%FT%T%z)" -o cmk cmk.go
This will always build for the current architecture that go is running on, in order to enable cross-compiling with go, you would need to set the environment variables
GOOS, and if on armhf
GOARM. Though note the
GOOS doesn’t really matter since snaps only build and run on linux (even if running from mac/windows using multipass as that’s really a linux VM) so that will always be the same.
go plugin will do this for you, setting the appropriate values of the environment variables when it calls go build. However, since you need to set some additional options to the
go build call it seems, you will need to set these environment variables yourself similar to something like:
... your other stuff here ...
case $SNAPCRAFT_ARCH_TRIPLET in
# TODO add other arches
GO111MODULE=on go build -mod=vendor -ldflags="-s -w -X main.GitSHA=$(git rev-parse --short HEAD) -X main.BuildDate=$(date +%FT%T%z)" -o cmk cmk.go
Note that I explicitly set GO111MODULE=on, that may or may not be necessary for you…