I follow this post:
https://blog.alexellis.io/serverless-golang-with-openfaas/
[faas-cli build -f gohash.yml]
here is the error:
[0] > Building gohash.
Clearing temporary build folder: ./build/gohash/
Preparing ./gohash/ ./build/gohash/function
Building: gohash:latest with go template. Please wait..
Sending build context to Docker daemon 38.91kB
Step 1/20 : FROM golang:1.9.7-alpine3.8 as builder
---> b0260be938c6
Step 2/20 : RUN apk --no-cache add curl && echo "Pulling watchdog binary from Github." && curl -sSL https://github.com/openfaas/faas/releases/download/0.9.6/fwatchdog > /usr/bin/fwatchdog && chmod +x /usr/bin/fwatchdog && apk del curl --no-cache
---> Using cache
---> 5e42443212b4
Step 3/20 : WORKDIR /go/src/handler
---> Using cache
---> b09e269be47c
Step 4/20 : COPY . .
---> Using cache
---> 1812be5338cd
Step 5/20 : 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; }
---> Using cache
---> 013ebc359837
Step 6/20 : RUN CGO_ENABLED=0 GOOS=linux go build --ldflags "-s -w" -a -installsuffix cgo -o handler . && go test $(go list ./... | grep -v /vendor/) -cover
---> Running in 6ae065e4f5fd
main.go:9:2: read /go/src/handler/function/gohash.go: unexpected NUL in input
The command '/bin/sh -c CGO_ENABLED=0 GOOS=linux go build --ldflags "-s -w" -a -installsuffix cgo -o handler . && go test $(go list ./... | grep -v /vendor/) -cover' returned a non-zero code: 1
2018/10/10 10:56:38 ERROR - Could not execute command: [docker build -t gohash:latest .]
My VS code is in UTF-8 encoding.
Here is the source code:
the dir is $gopath/src/
Hey there @FlankMiao . Your handler.go is binary file which is the problem here I think. The right order for writing your first function is:
is whatever name you gave to your function
faas-cli new <fn_name> --lang=go --prefix=<dockerhubname> prefix is optional in case you are pushing in dockehub or other image repositoryfaas-cli as you didAlso you should not run any go .. commands on your handler.go file. I hope this resolves your issue.
Edit: If the steps above don't help please provide me with the steps you did before building your function.
@martindekov thanks :), there is an encrypt software in my laptop, I guess it,s the reason. I will try again.
@martindekov It.s caused by the encryption software. Thanks :).
I am glad you got your issue resolved. 馃憤