Closed willfore closed 2 years ago
Hi Billy,
The version of the template you have has other changes, which means the import should be updated for your function to point at github.com/openfaas/templates-sdk/go-http
Here is an example of what it should look like now:
package function
import (
"fmt"
"net/http"
handler "github.com/openfaas/templates-sdk/go-http"
)
// Handle a function invocation
func Handle(req handler.Request) (handler.Response, error) {
var err error
message := fmt.Sprintf("Body: %s", string(req.Body))
return handler.Response{
Body: []byte(message),
StatusCode: http.StatusOK,
}, err
}
This then gives:
$ go mod tidy
go: finding module for package github.com/openfaas/templates-sdk/go-http
go: downloading github.com/openfaas/templates-sdk/go-http v0.0.0-20220408082716-5981c545cb03
go: downloading github.com/openfaas/templates-sdk v0.0.0-20220408082716-5981c545cb03
go: found github.com/openfaas/templates-sdk/go-http in github.com/openfaas/templates-sdk/go-http v0.0.0-20220408082716-5981c545cb03
This is my go.mod file for a test function:
module handler/function
go 1.18
require github.com/openfaas/templates-sdk/go-http v0.0.0-20220408082716-5981c545cb03
Let me know if this resolves the problem you're facing.
Alternatively, you can always pin an older version of a template if that suits your needs (#branch
#tag
#release
):
faas-cli template pull https://github.com/openfaas/golang-http-template#0.4.0
Fetch templates from repository: https://github.com/openfaas/golang-http-template at 0.4.0
2022/05/02 15:40:15 Attempting to expand templates from https://github.com/openfaas/golang-http-template
2022/05/02 15:40:16 Fetched 2 template(s) : [golang-http golang-middleware] from https://github.com/openfaas/golang-http-template
Alex
I made the suggested changes after go mod tidy I have the following in go.mod
module myfunc
go 1.18
require (
github.com/google/uuid v1.3.0
github.com/honeybadger-io/honeybadger-go v0.5.0
github.com/openfaas/templates-sdk/go-http v0.0.0-20220408082716-5981c545cb03
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
)
require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/pborman/uuid v1.2.0 // indirect
github.com/shirou/gopsutil v2.18.12+incompatible // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
)
When publishing now I run into
`#26 [build 13/13] RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -installsuffix cgo -o handler .
I have GO111MODULE
set to on
changing module name from myfunc
to handler/function
fixed the issue.
OK to close the issue?
All good.
/lock: resolved
If anyone else has similar issues, feel free to open your own issue on GitHub.
Needed to make use of Go 1.17 modules. Followed guide to upgrade the template:
Inside of func folder did the following:
rm -rf template/golang-http template/golang-middleware
Install new templates
faas-cli template store pull golang-http
Tidy modules
go mod tidy
Try to publish function and get the following error:
Expected Behaviour
Upgrade template and publish app
Your Environment
FaaS-CLI version ( Full output from:
faas-cli version
):Docker version
docker version
(e.g. Docker 17.0.05 ): Client: Cloud integration: v1.0.22 Version: 20.10.12 API version: 1.41 Go version: go1.16.12 Git commit: e91ed57 Built: Mon Dec 13 11:46:56 2021 OS/Arch: darwin/arm64 Context: default Experimental: trueServer: Docker Engine - Community Engine: Version: 20.10.12 API version: 1.41 (minimum version 1.12) Go version: go1.16.12 Git commit: 459d0df Built: Mon Dec 13 11:43:07 2021 OS/Arch: linux/arm64 Experimental: false containerd: Version: 1.4.12 GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d runc: Version: 1.0.2 GitCommit: v1.0.2-0-g52b36a2 docker-init: Version: 0.19.0 GitCommit: de40ad0